Write all the clauses of a compiled module to a file. The first argument is the name of
the module to save, the second is the name of the file which will be created or
overwritten with the data from the module. The filename must be an atom enclosed by single
or double quotes.
The last argument is a list of options on how to save the module, the available options
are:
The blowfish encryption algorithm is used to encrypt the files, the size of the key is 128 bits. This key is generated by using the supplied password as input to initialize the encryption key. Because a good password is required Trinc-Prolog checks the entered passwords. The rules for password checking are:
| Password examples | |
| test2_ | this password is too short |
| test2test | there is no symbolic or special character in the password |
| test2_test | this is a correct password, it contains a number ('2') and a symbol character ('_'). |
The blowfish encryption algorithm is free to use, there are no patents restraining its use and also no export restrictions, it was introduced by Bruce Schneier in 1994. For more information about the blowfish encryption algorithm visit the website of Counterpane: www.counterpane.com.
| To protect the contents of encrypted modules it is not possible to use the clause/2 predicate for these modules. |
The text editor can also encrypt and decrypt files, for more information see: text editor.
The first parameter of the encrypt/2 save-option determines how the encryption password is managed by the person that will decrypt the file. The three available options are:
Trinc-Prolog can detect if the entered password was correct, it does that by calculating an MD5 digest for the original data being encrypted and comparing it with the MD5 digest calculated while decrypting. Incorrect passwords are never stored. The MD5 digest algorithm is described in rfc1321.
As can be seen from the example below two backslash characters are used to separate folders, two backslash characters are used to make sure that a part of a filename is not interpreted as an escape sequence, for instance each '\t' character sequence is replaced by the compiler by a single tab character. For more information about this see escape sequences and symbolic control characters.
see also: active_module/1 check_singleton/1 close_all_modules/0 close_module/1 consult/0 consult/1 consult/3 create_module/1 create_module/2 ensure_loaded/1 include/1 module/3 module_name/2 modules open_module/0 open_module/1 open_module/3 open_module_search/3 open_standard_module/2 save_module/1 save_module/2 set_active_module/0 set_active_module/1 this_module/3
| Example | |
| save_module(m1, 'c:\\mod1.gz', [compress]). | the clauses of the module m1 are written compressed to the file "c:\mod.txt" |
| save_module(m1, 'c:\\mod1.gz', [encrypt(store_key, 'test2_test')]). | the clauses of the module m1 are encrypted and then written to the file "c:\mod.txt", the key used for encryption will be stored inside the file and 'test2_test' is the key used for encryption |
| save_module(m1, 'c:\\mod1.gz', [compress, encrypt(ask_key, 'key2+enc']). | the clauses of the module m1 are compressed, encrypted.and then written to the file "c:\mod.txt", 'ask_key' means that the key used for encryption must be entered by the user opening the module, on opening the module the user may store the key |
| Exceptions | |
| the argument is a variable | an instantiation_error exception is thrown |
| the argument is not an atom | a type_error(atom, A) exception is thrown |
| the open-mode is not readwrite | a permission_error(save, module, A) exception is thrown |
| no module with the specified name | a existence_error(module, A) exception is thrown |
| error while writing to file | a permission_error(write, file, A) exception is thrown |
| save_options is a variable | an instantiation_error exception is thrown |
| save_options is not a list | a type_error(list, A) exception is thrown |
| an element E of the list save_options is a variable | an instantiation_error exception is thrown |
| an element E of the list save_options is not a valid option | a domain_error(save_module_option, E) is thrown |
| the password P to use for encryption is not correct | a evaluation_error(weak_encryption_key, P) exception is thrown |