You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

enigma_driver.php 4.2KB

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