pikirasa
pikirasa copied to clipboard
Adding an interface to the RSA class
Hi!
Why not adding an interface to the RSA class ? I'm thinking about using your solution but I'd like having an interface for DI and SOLID purposes...
In fact, i'd like to be able to make an adapter to your class.
Just a suggestion:
- Create the interface:
<?php
namespace Pikirasa;
interface RSAInterface
{
/*
* Minimum key size bits
*/
const MINIMUM_KEY_SIZE = 128;
/*
* Default key size bits
*/
const DEFAULT_KEY_SIZE = 2048;
public function fixKeyArgument($keyFile);
/**
* Creates a new RSA key pair with the given key size
*
* @param null $keySize RSA Key Size in bits
* @param bool $overwrite Overwrite existing key files
* @return bool Result of creation
*
* @throws Pikirasa\Exception
*/
public function create($keySize = null, $overwrite = false);
/**
* Get public key to be used during encryption and decryption
*
* @return string Certificate public key string or stream path
*/
public function getPublicKeyFile();
/**
* Get private key to be used during encryption and decryption
*
* @return string Certificate private key string or stream path
*/
public function getPrivateKeyFile();
/**
* Set password to be used during encryption and decryption
*
* @param string $password Certificate password
*/
public function setPassword($password);
/**
* Encrypt data with provided public certificate
*
* @param string $data Data to encrypt
* @return string Encrypted data
*
* @throws Pikirasa\Exception
*/
public function encrypt($data);
/**
* Encrypt data and then base64_encode it
*
* @param string $data Data to encrypt
* @return string Base64-encrypted data
*/
public function base64Encrypt($data);
/**
* Decrypt data with provided private certificate
*
* @param string $data Data to encrypt
* @return string Decrypted data
*
* @throws Pikirasa\Exception
*/
public function decrypt($data);
/**
* base64_decode data and then decrypt it
*
* @param string $data Base64-encoded data to decrypt
* @return string Decrypted data
*/
public function base64Decrypt($data);
}
- Update the RSA class with the interface impl:
<?php
namespace Pikirasa;
class RSA implements RSAInterface
{
// ... you can keep the same code and even use @inheritDoc to use the interface's annotations
}