/* */ #ifndef _D_LIBGCRYPT_ARC4_ENCRYPTOR_H_ #define _D_LIBGCRYPT_ARC4_ENCRYPTOR_H_ #include "common.h" #include "DlAbortEx.h" #include "LibgcryptARC4Context.h" #include "StringFormat.h" #include namespace aria2 { class ARC4Encryptor { private: LibgcryptARC4Context _ctx; void handleError(gcry_error_t err) const { throw DlAbortEx (StringFormat("Exception in libgcrypt routine(ARC4Encryptor class): %s", gcry_strerror(err)).str()); } public: ARC4Encryptor() {} ~ARC4Encryptor() {} void init(const unsigned char* key, size_t keyLength) { _ctx.init(key, keyLength); } void encrypt(unsigned char* out, size_t outLength, const unsigned char* in, size_t inLength) { gcry_error_t r = gcry_cipher_encrypt(_ctx.getCipherContext(), out, outLength, in, inLength); if(r) { handleError(r); } } }; } // namespace aria2 #endif // _D_LIBGCRYPT_ARC4_ENCRYPTOR_H_