[CLEANUP] The correct case must be used for standard PHP types in phpdoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Backend / AbstractBackend.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Backend;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * This class contains an abstract SSL backend for the TYPO3 RSA authentication
19 * service.
20 *
21 * There are two steps:
22 * - prepare data for encoding
23 * - decode incoming data
24 *
25 * To prepare data for encoding, the createNewKeyPair() method should be called.
26 * This method returns an instance of \TYPO3\CMS\Rsaauth\Keypair class, which contains
27 * the private and public keys. Public key is sent to the client to encode data.
28 * Private key should be stored somewhere (preferably in user's session).
29 *
30 * To decode data, the decrypt() method should be called with the private key
31 * created at the previous step and the data to decode. If the data is decoded
32 * successfully, the result is a string. Otherwise it is NULL.
33 */
34 abstract class AbstractBackend
35 {
36 /**
37 * Error message for the last operation. Derived classes should always set
38 * or clear this variable inside the createNewKeyPair() or decypt().
39 *
40 * @var string
41 */
42 protected $error = '';
43
44 /**
45 * Creates a new key pair for the encryption or gets the existing key pair (if one already has been generated).
46 *
47 * There should only be one key pair per request because the second private key would overwrites the first private
48 * key. So the submitting the form with the first public key would not work anymore.
49 *
50 * @return \TYPO3\CMS\Rsaauth\Keypair|null a key pair or NULL in case of error
51 */
52 abstract public function createNewKeyPair();
53
54 /**
55 * Decripts the data using the private key.
56 *
57 * @param string $privateKey The private key (obtained from a call to createNewKeyPair())
58 * @param string $data Data to decrypt (base64-encoded)
59 * @return string Decrypted data or NULL in case of an error
60 */
61 abstract public function decrypt($privateKey, $data);
62
63 /**
64 * Checks if this backend is available for calling.
65 *
66 * @return bool
67 */
68 abstract public function isAvailable();
69
70 /**
71 * Retrieves an error message.
72 *
73 * @return string An error message or empty string if there were no error
74 */
75 public function getLastError()
76 {
77 return $this->error;
78 }
79 }