0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 +-------------------------------------------------------------------------+
|
|
5 | Abstract driver for the Enigma Plugin |
|
|
6 | |
|
|
7 | Copyright (C) 2010-2015 The Roundcube Dev Team |
|
|
8 | |
|
|
9 | Licensed under the GNU General Public License version 3 or |
|
|
10 | any later version with exceptions for skins & plugins. |
|
|
11 | See the README file for a full license statement. |
|
|
12 | |
|
|
13 +-------------------------------------------------------------------------+
|
|
14 | Author: Aleksander Machniak <alec@alec.pl> |
|
|
15 +-------------------------------------------------------------------------+
|
|
16 */
|
|
17
|
|
18 abstract class enigma_driver
|
|
19 {
|
|
20 /**
|
|
21 * Class constructor.
|
|
22 *
|
|
23 * @param string User name (email address)
|
|
24 */
|
|
25 abstract function __construct($user);
|
|
26
|
|
27 /**
|
|
28 * Driver initialization.
|
|
29 *
|
|
30 * @return mixed NULL on success, enigma_error on failure
|
|
31 */
|
|
32 abstract function init();
|
|
33
|
|
34 /**
|
|
35 * Encryption (and optional signing).
|
|
36 *
|
|
37 * @param string Message body
|
|
38 * @param array List of keys (enigma_key objects)
|
|
39 * @param enigma_key Optional signing Key ID
|
|
40 *
|
|
41 * @return mixed Encrypted message or enigma_error on failure
|
|
42 */
|
|
43 abstract function encrypt($text, $keys, $sign_key = null);
|
|
44
|
|
45 /**
|
|
46 * Decryption (and sig verification if sig exists).
|
|
47 *
|
|
48 * @param string Encrypted message
|
|
49 * @param array List of key-password
|
|
50 * @param enigma_signature Signature information (if available)
|
|
51 *
|
|
52 * @return mixed Decrypted message or enigma_error on failure
|
|
53 */
|
|
54 abstract function decrypt($text, $keys = array(), &$signature = null);
|
|
55
|
|
56 /**
|
|
57 * Signing.
|
|
58 *
|
|
59 * @param string Message body
|
|
60 * @param enigma_key The signing key
|
|
61 * @param int Signing mode (enigma_engine::SIGN_*)
|
|
62 *
|
|
63 * @return mixed True on success or enigma_error on failure
|
|
64 */
|
|
65 abstract function sign($text, $key, $mode = null);
|
|
66
|
|
67 /**
|
|
68 * Signature verification.
|
|
69 *
|
|
70 * @param string Message body
|
|
71 * @param string Signature, if message is of type PGP/MIME and body doesn't contain it
|
|
72 *
|
|
73 * @return mixed Signature information (enigma_signature) or enigma_error
|
|
74 */
|
|
75 abstract function verify($text, $signature);
|
|
76
|
|
77 /**
|
|
78 * Key/Cert file import.
|
|
79 *
|
|
80 * @param string File name or file content
|
|
81 * @param bolean True if first argument is a filename
|
|
82 * @param array Optional key => password map
|
|
83 *
|
|
84 * @return mixed Import status array or enigma_error
|
|
85 */
|
|
86 abstract function import($content, $isfile = false, $passwords = array());
|
|
87
|
|
88 /**
|
|
89 * Key/Cert export.
|
|
90 *
|
|
91 * @param string Key ID
|
|
92 * @param bool Include private key
|
|
93 * @param array Optional key => password map
|
|
94 *
|
|
95 * @return mixed Key content or enigma_error
|
|
96 */
|
|
97 abstract function export($key, $with_private = false, $passwords = array());
|
|
98
|
|
99 /**
|
|
100 * Keys listing.
|
|
101 *
|
|
102 * @param string Optional pattern for key ID, user ID or fingerprint
|
|
103 *
|
|
104 * @return mixed Array of enigma_key objects or enigma_error
|
|
105 */
|
|
106 abstract function list_keys($pattern = '');
|
|
107
|
|
108 /**
|
|
109 * Single key information.
|
|
110 *
|
|
111 * @param string Key ID, user ID or fingerprint
|
|
112 *
|
|
113 * @return mixed Key (enigma_key) object or enigma_error
|
|
114 */
|
|
115 abstract function get_key($keyid);
|
|
116
|
|
117 /**
|
|
118 * Key pair generation.
|
|
119 *
|
|
120 * @param array Key/User data (name, email, password, size)
|
|
121 *
|
|
122 * @return mixed Key (enigma_key) object or enigma_error
|
|
123 */
|
|
124 abstract function gen_key($data);
|
|
125
|
|
126 /**
|
|
127 * Key deletion.
|
|
128 *
|
|
129 * @param string Key ID
|
|
130 *
|
|
131 * @return mixed True on success or enigma_error
|
|
132 */
|
|
133 abstract function delete_key($keyid);
|
|
134
|
|
135 /**
|
|
136 * Returns a name of the hash algorithm used for the last
|
|
137 * signing operation.
|
|
138 *
|
|
139 * @return string Hash algorithm name e.g. sha1
|
|
140 */
|
|
141 abstract function signature_algorithm();
|
|
142 }
|