misc.js

Summary
misc.js
Constants
FireGPG.Const.VersionThe current version of FireGPG
FireGPG.Const.VersionAThe current verion of FireGPG without dots
FireGPG.Const.StatusThe status of the FireGPG’s code.
FireGPG.Const.SvnThe current subversion’s revision number, for this file !
Functions
FireGPG.debugCheck if debuggin is enabled and if yes show up messages in console
Constants
Id for components.
Tempory files
Write modes for files.
Variables
savedPasswordThe password of the private key, saved for later actions.
oldKeyIDThe previous key selected.
updateAvailableTrue if an update of FireGPG is available
Functions
choosePublicKeyShow a dialog (list.xul) to choose a list of public keys (array).
choosePrivateKeyShow a dialog (list.xul) to choose a private key.
showTextShow ‘text’ in a dialog (the editor)
showEditorOpen the editor (the showtext.xul dialog)
getPasswordShow the generic dialog to get a password.
savePassword
getSavedPassword
getPrivateKeyPasswordThis uses getPassword:function () to get a password for a private key.
getsavedPasswordReturn the saved password
eraseSavedPasswordThis erase the saved password :function (it’s for exemple when a sign failled)
getSelfKeywho return a private key for the user :function (the default or the one selected in the list) null is returned if no key is selected.
getTmpDirGet the path of a tmp file.
getTmpFileGet an unique temporary file name.
removeFileDelete a file.
fileExistReturn true if a file exist
putIntoFileSave data to a file.
getFromFileGet the content of a file
putIntoBinFileSave data to a file, in binary mode.
getBinContentGet the content of a binary file
getContentGet the content of a resource form anywhere (like chrome://)
getContentXtttpGet the content of a web resource by using a xmlhttprequest.
testIfSomethingsIsNewTest if user update FireGPG or if he have to update, and show the What is new page send a ping or propose to update FireGPG if relevant.
showUpdateDialogShow the update dialog to let user update FireGPG
htmlEncodeEncode special chars (&, <, > et “) to they html values.
gmailWrappingThis fuction approximates gmail’s line-wrapping rules, so that a message can be wrapped before it’s signed, instead of after, which would break the signature.
wrapThis function wraps a single line of text into multiple lines, each no longer than limit, unless a single word is too long.
genreate_api_keyGenerate and random string between 64 and 128 charactes, probably unique.
trimRemove extra space at the end and the begging of the string.
TrimAndWashRemove extra space at the end and the begging of the string, and remove \n
EnigConvertGpgToUnicodeConvert the gpg --with-collums text (who are strangly encoded) into a uniform Unicode string.
EnigConvertToUnicodeConvert the text, in the specified chaset, into an Unicode string.
EnigConvertFromUnicodeConvert the text, in unicode, into an string in the specified chaset.
CreateTreeItemKeyReturn a Treeitem for the key in parameter
CreateTreeItemKey2Return a Treeitem for the key in parameter
setSkinForKeySet the correct class of a key, using his status (private, revoked)
CreateTreeItemKey3Return a Treeitem for the key in parameter
setSkinForKey2Set class for a node with the key attribute
getKeyServerReturn the current key server
showSearchBoxShow the dialog box to search key
convertCRLFToStandartsConvert CR to CRLF, LF to CRLF and keep CRLF
dumperThis function was inspired by the print_r function of PHP.
dump2Show an array or an object in a console
UTF8Class to handle UTF8 tests.
Functions
encodeEncode a text to utf8
decodeDecode a utf8 text
Base64Class to handle base64 encoding http://www.webtoolkit.info/
Variables
_keyStrValid base64 chars
Functions
encodeEncode to base6
decodeDecode a base64 string
_utf8_encodeEncode a string to utf8
_utf8_decodeDecode string from utf8
pgpencodeUseless function who do nothing
getFileExtentionReturn the extention of a file

Constants

FireGPG.Const.Version

The current version of FireGPG

FireGPG.Const.VersionA

The current verion of FireGPG without dots

FireGPG.Const.Status

The status of the FireGPG’s code.  Can be DEVEL or RELASE.  Use RELASE only for.. relases ;).

FireGPG.Const.Svn

The current subversion’s revision number, for this file !

Functions

FireGPG.debug

FireGPG.debug = function(message,
debugCode,
fatal)

Check if debuggin is enabled and if yes show up messages in console

Paramters

messageThe message
debugCodeThe position in the code
fatalTrue if it’s a fatal error.

Constants

Id for components.

NS_LOCALEFILE_CONTRACTIDId for the component @mozilla.org/file/local;1
NS_DIRECTORYSERVICE_CONTRACTIDId for the component @mozilla.org/file/directory_service;1
NS_NETWORKOUTPUT_CONTRACTIDId for the component @mozilla.org/network/file-output-stream;1
NS_NETWORKINPUT_CONTRACTIDId for the @mozilla.org/network/file-input-stream;1
NS_NETWORKINPUTS_CONTRACTIDId for the component @mozilla.org/scriptableinputstream;1
NS_PROCESSUTIL_CONTRACTIDId for the component @mozilla.org/process/util;1

Tempory files

TMP_DIRECTORYThe base name for files (doesn’t same to be a directory)
TMP_FILESThe file name for common files.
TMP_RFILESThe file name for executable scripts.
TMP_EFILESThe file name for executables..

Write modes for files.

WRITE_MODEThe default mode for files.
WRITE_PERMISSIONThe default permission for files
WRITE_PERMISSION_RThe default permission for executable files

Variables

savedPassword

The password of the private key, saved for later actions.

oldKeyID

The previous key selected.

updateAvailable

True if an update of FireGPG is available

Functions

choosePublicKey

choosePublicKey: function(preSelect)

Show a dialog (list.xul) to choose a list of public keys (array). null is returned if the public key is not choosed

Paramters

preSelectOptional.  And array of keys to preselect.

choosePrivateKey

choosePrivateKey:function (preSelect)

Show a dialog (list.xul) to choose a private key. null is returned if no keys are chosen.

Parameters

preSelectOptional.  A list of key to preselect

showText

showText:function (text,
description,
title,
doShowButtons,
validSign)

Show ‘text’ in a dialog (the editor)

Parameters

textThe text to show display
descriptionOptional.  The message to show.  If not set, use the default.
titleOptional.  The title of the window.  If not set, use the default.
doShowButtonsOptional.  If we have to show buttons to encrypt and so.  Default to false.
validSignOptional.  The message for the validSign field.

showEditor

showEditor:function ()

Open the editor (the showtext.xul dialog)

getPassword

getPassword:function (question,
save_password,
domain,
nosavecheckbox)

Show the generic dialog to get a password.

An object is returned : {password: “password”, save_password: true/false}$

null is returned if cancel button is clicked.

Parameters

questionThe text to show for the prompt.
save_passwordOptional.  The default value for the save password checkbox.  If not set, value set in the options by the user is used.
domainOptional.  Say the password is asked form this page and disable the savepassword checkbox.
nosavecheckboxOptional.  Disable the save password feature

savePassword

savePassword:function (password)
  • TODO !* Save a password in the password manager of Firefox

Parameters

passwordThe password

getSavedPassword

getSavedPassword:function ()
  • TODO !* Get the password saved in the password manager of Firefox

getPrivateKeyPassword

getPrivateKeyPassword:function (useSavedPassword *default =  true */,
domain *default =  false*/,
message *default =  false*/,
 nosavecheckbox  )

This uses getPassword:function () to get a password for a private key.

It’s the user request for it, it’s save the password for later.

If useSavedPassword = false, the password is asked each time, even if it’s already saved in the global variable savedPassword.

null is returned on error.

Parameters

useSavedPasswordOptional.  Set this to false to disable the use of a saved password
domainOptional.  The domain to pass to getPassword.
messageOptional.  The message to ask the user.
nosavecheckboxOptional.  Disable the save password feature

getsavedPassword

getsavedPassword:function ()

Return the saved password

eraseSavedPassword

eraseSavedPassword:function ()

This erase the saved password :function (it’s for exemple when a sign failled)

getSelfKey

getSelfKey:function (autoSelectPrivate)

who return a private key for the user :function (the default or the one selected in the list) null is returned if no key is selected.

Parameters

autoSelectPrivateOptional.  A list of key to autoselect

getTmpDir

getTmpDir:function ()

Get the path of a tmp file.  The path is returned.

getTmpFile

getTmpFile:function (permission /* optional */,
 suffix_file)

Get an unique temporary file name.  The path + filename is returned.

Parameters

permissionOptional.  The permission of the file.  See Write modes for files
suffix_fileOptional.  A suffix to add to the default file name.

removeFile

removeFile:function (path)

Delete a file.

Parameters

pathThe file to delete.

fileExist

fileExist:function (path)

Return true if a file exist

Parameters

pathThe file to delete.

putIntoFile

putIntoFile:function (filename,
data)

Save data to a file.  File saved in UTF-8 charset.

Parameters

filenameThe name of the file
dataThe data to save

getFromFile

getFromFile:function (filename,
charset)

Get the content of a file

Parameters

filenameThe location of the file.
charsetOptional.  The charset of the file.  Default to UTF-8

putIntoBinFile

putIntoBinFile:function (filename,
data)

Save data to a file, in binary mode.

Parameters

filenameThe name of the file
dataThe data to save

getBinContent

getBinContent:function (aURL,
maxData)

Get the content of a binary file

Parameters

aURLThe location of the file.
maxDataOptional.  The max length of data to get.  {MAX} is returned if there is too data

getContent

getContent:function (aURL)

Get the content of a resource form anywhere (like chrome://)

Parameters

aURLThe location of the resource.

getContentXtttp

Get the content of a web resource by using a xmlhttprequest.

Parameters

urlThe url of the resource

testIfSomethingsIsNew

testIfSomethingsIsNew:function ()

Test if user update FireGPG or if he have to update, and show the What is new page send a ping or propose to update FireGPG if relevant.

showUpdateDialog

showUpdateDialog:function ()

Show the update dialog to let user update FireGPG

htmlEncode

htmlEncode:function (s)

Encode special chars (&, <, > et “) to they html values.

Parameters

sThe text.

gmailWrapping

gmailWrapping:function (text)

This fuction approximates gmail’s line-wrapping rules, so that a message can be wrapped before it’s signed, instead of after, which would break the signature.

Parameters

textThe text.

wrap

wrap:function (text,
limit)

This function wraps a single line of text into multiple lines, each no longer than limit, unless a single word is too long.

Parameters

textThe text.
limitThe maximum characters for one line.

genreate_api_key

genreate_api_key:function ()

Generate and random string between 64 and 128 charactes, probably unique.  This is usefull for the api.

trim

trim :function (str)

Remove extra space at the end and the begging of the string.

Parameters

strThe string

TrimAndWash

TrimAndWash:function (str)

Remove extra space at the end and the begging of the string, and remove \n

Parameters

strThe string

EnigConvertGpgToUnicode

EnigConvertGpgToUnicode:function (text)

Convert the gpg --with-collums text (who are strangly encoded) into a uniform Unicode string.

This function is from Enigmail, same license as FireGPG.Core.

Parameters

textThe text to convert

EnigConvertToUnicode

EnigConvertToUnicode:function (text,
charset)

Convert the text, in the specified chaset, into an Unicode string.  This function is from Enigmail, same license as FireGPG.Core.

Parameters

textThe text to convert
charsetThe charset of the text.

EnigConvertFromUnicode

EnigConvertFromUnicode:function (text,
charset)

Convert the text, in unicode, into an string in the specified chaset.  This function is from Enigmail, same license as FireGPG.Core.

Parameters

textThe text to convert
charsetThe charset of the text.

CreateTreeItemKey

CreateTreeItemKey:function (key,
document,
forceId)

Return a Treeitem for the key in parameter

Parameters

keyThe key
documentThe current document.
forceIdIf we have to force the id of the key

CreateTreeItemKey2

CreateTreeItemKey2:function (key,
document,
forceId,
privateKey,
subkey)

Return a Treeitem for the key in parameter

Parameters

keyThe key
documentThe current document.
forceIdIf we have to force the id of the key
privateKeyTrue if it’s a private key
subkeyTrue if it’s a subkey

setSkinForKey

setSkinForKey:function (key,
child,
privateKey)

Set the correct class of a key, using his status (private, revoked)

Parameters

keyThe key
childThe element
privateKEyTrue if it’s a private key

CreateTreeItemKey3

CreateTreeItemKey3:function (key,
document,
mainKey,
sign,
havePrivate)

Return a Treeitem for the key in parameter

Parameters

keyThe key
documentThe current document.
mainKeyThe partent key of the key
signThe sign of the key
havePrivateIf the user have the private key

setSkinForKey2

setSkinForKey2:function (key,
child,
mainKey,
sign,
havePrivate)

Set class for a node with the key attribute

Parameters

keyThe key
childThe node
mainKeyThe partent key of the key
signThe sign of the key
havePrivateIf the user have the private key

getKeyServer

getKeyServer:function ()

Return the current key server

showSearchBox

showSearchBox:function (autoSearch)

Show the dialog box to search key

Paramters

autoSearchPreset the search field

convertCRLFToStandarts

convertCRLFToStandarts:function (text)

Convert CR to CRLF, LF to CRLF and keep CRLF

Parameters

textThe text

dumper

dumper:function (arr,
level)

This function was inspired by the print_r function of PHP.  This will accept some data as the argument and return a text that will be a more readable version of the array/hash/object that is given.

Paramters

arrThe object
levelThe current level of the dump

dump2

dump2:function (o)

Show an array or an object in a console

Parameters

oThe object

UTF8

Class to handle UTF8 tests.  http://snippets.dzone.com/posts/show/5294

Summary
Functions
encodeEncode a text to utf8
decodeDecode a utf8 text

Functions

encode

encode: function(s)

Encode a text to utf8

Parameters

sThe text

decode

decode: function(s)

Decode a utf8 text

Parameters

sThe text

Base64

Class to handle base64 encoding http://www.webtoolkit.info/

Summary
Variables
_keyStrValid base64 chars
Functions
encodeEncode to base6
decodeDecode a base64 string
_utf8_encodeEncode a string to utf8
_utf8_decodeDecode string from utf8
pgpencodeUseless function who do nothing
getFileExtentionReturn the extention of a file

Variables

_keyStr

_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

Valid base64 chars

Functions

encode

encode: function (input,
bMode)

Encode to base6

Parameters

inputThe text
bModeConvert to utf8

decode

decode : function (input,
bMode)

Decode a base64 string

Paramters

inputThe text
bModeDecode from utf8

_utf8_encode

_utf8_encode:function (string)

Encode a string to utf8

Parameters

stringThe string

_utf8_decode

_utf8_decode :function (utftext)

Decode string from utf8

Parameters

utftextThe text

pgpencode

pgpencode: function(texte)

Useless function who do nothing

Parameters

texteA variable.  Cool.

getFileExtention

getFileExtention:function (filename)

Return the extention of a file

Parameters

filenameThe file name
FireGPG.debug = function(message,
debugCode,
fatal)
Check if debuggin is enabled and if yes show up messages in console
choosePublicKey: function(preSelect)
Show a dialog (list.xul) to choose a list of public keys (array).
choosePrivateKey:function (preSelect)
Show a dialog (list.xul) to choose a private key.
showText:function (text,
description,
title,
doShowButtons,
validSign)
Show ‘text’ in a dialog (the editor)
showEditor:function ()
Open the editor (the showtext.xul dialog)
getPassword:function (question,
save_password,
domain,
nosavecheckbox)
Show the generic dialog to get a password.
savePassword:function (password)
getSavedPassword:function ()
getPrivateKeyPassword:function (useSavedPassword *default =  true */,
domain *default =  false*/,
message *default =  false*/,
 nosavecheckbox  )
This uses getPassword:function () to get a password for a private key.
getsavedPassword:function ()
Return the saved password
eraseSavedPassword:function ()
This erase the saved password :function (it’s for exemple when a sign failled)
getSelfKey:function (autoSelectPrivate)
who return a private key for the user :function (the default or the one selected in the list) null is returned if no key is selected.
getTmpDir:function ()
Get the path of a tmp file.
getTmpFile:function (permission /* optional */,
 suffix_file)
Get an unique temporary file name.
removeFile:function (path)
Delete a file.
fileExist:function (path)
Return true if a file exist
putIntoFile:function (filename,
data)
Save data to a file.
getFromFile:function (filename,
charset)
Get the content of a file
putIntoBinFile:function (filename,
data)
Save data to a file, in binary mode.
getBinContent:function (aURL,
maxData)
Get the content of a binary file
getContent:function (aURL)
Get the content of a resource form anywhere (like chrome://)
testIfSomethingsIsNew:function ()
Test if user update FireGPG or if he have to update, and show the What is new page send a ping or propose to update FireGPG if relevant.
showUpdateDialog:function ()
Show the update dialog to let user update FireGPG
htmlEncode:function (s)
Encode special chars (&, <, > et “) to they html values.
gmailWrapping:function (text)
This fuction approximates gmail’s line-wrapping rules, so that a message can be wrapped before it’s signed, instead of after, which would break the signature.
wrap:function (text,
limit)
This function wraps a single line of text into multiple lines, each no longer than limit, unless a single word is too long.
genreate_api_key:function ()
Generate and random string between 64 and 128 charactes, probably unique.
trim :function (str)
Remove extra space at the end and the begging of the string.
TrimAndWash:function (str)
Remove extra space at the end and the begging of the string, and remove \n
EnigConvertGpgToUnicode:function (text)
Convert the gpg --with-collums text (who are strangly encoded) into a uniform Unicode string.
EnigConvertToUnicode:function (text,
charset)
Convert the text, in the specified chaset, into an Unicode string.
EnigConvertFromUnicode:function (text,
charset)
Convert the text, in unicode, into an string in the specified chaset.
CreateTreeItemKey:function (key,
document,
forceId)
Return a Treeitem for the key in parameter
CreateTreeItemKey2:function (key,
document,
forceId,
privateKey,
subkey)
Return a Treeitem for the key in parameter
setSkinForKey:function (key,
child,
privateKey)
Set the correct class of a key, using his status (private, revoked)
CreateTreeItemKey3:function (key,
document,
mainKey,
sign,
havePrivate)
Return a Treeitem for the key in parameter
setSkinForKey2:function (key,
child,
mainKey,
sign,
havePrivate)
Set class for a node with the key attribute
getKeyServer:function ()
Return the current key server
showSearchBox:function (autoSearch)
Show the dialog box to search key
convertCRLFToStandarts:function (text)
Convert CR to CRLF, LF to CRLF and keep CRLF
dumper:function (arr,
level)
This function was inspired by the print_r function of PHP.
dump2:function (o)
Show an array or an object in a console
encode: function(s)
Encode a text to utf8
decode: function(s)
Decode a utf8 text
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
Valid base64 chars
encode: function (input,
bMode)
Encode to base6
decode : function (input,
bMode)
Decode a base64 string
_utf8_encode:function (string)
Encode a string to utf8
_utf8_decode :function (utftext)
Decode string from utf8
pgpencode: function(texte)
Useless function who do nothing
getFileExtention:function (filename)
Return the extention of a file
Close