/* */ #ifndef _D_LIBSSL_ARC4_ENCRYPTOR_H_ #define _D_LIBSSL_ARC4_ENCRYPTOR_H_ #include "common.h" #include #include #include "DlAbortEx.h" #include "LibsslARC4Context.h" #include "StringFormat.h" namespace aria2 { class ARC4Encryptor { private: LibsslARC4Context _ctx; void handleError() const { throw DL_ABORT_EX (StringFormat("Exception in libssl routine(ARC4Encryptor class): %s", ERR_error_string(ERR_get_error(), 0)).str()); } public: ARC4Encryptor() {} ~ARC4Encryptor() {} void init(const unsigned char* key, size_t keyLength) { _ctx.init(key, keyLength, 1); } void encrypt(unsigned char* out, size_t outLength, const unsigned char* in, size_t inLength) { int soutLength = outLength; if(!EVP_CipherUpdate(_ctx.getCipherContext(), out, &soutLength, in, inLength)) { handleError(); } } }; } // namespace aria2 #endif // _D_LIBSSL_ARC4_ENCRYPTOR_H_