PK.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2020, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #ifndef KERNEL
  9. # include <AK/DeprecatedString.h>
  10. #endif
  11. namespace Crypto {
  12. namespace PK {
  13. // FIXME: Fixing name up for grabs
  14. template<typename PrivKeyT, typename PubKeyT>
  15. class PKSystem {
  16. public:
  17. using PublicKeyType = PubKeyT;
  18. using PrivateKeyType = PrivKeyT;
  19. PKSystem(PublicKeyType& pubkey, PrivateKeyType& privkey)
  20. : m_public_key(pubkey)
  21. , m_private_key(privkey)
  22. {
  23. }
  24. PKSystem() = default;
  25. virtual void encrypt(ReadonlyBytes in, Bytes& out) = 0;
  26. virtual void decrypt(ReadonlyBytes in, Bytes& out) = 0;
  27. virtual void sign(ReadonlyBytes in, Bytes& out) = 0;
  28. virtual void verify(ReadonlyBytes in, Bytes& out) = 0;
  29. #ifndef KERNEL
  30. virtual DeprecatedString class_name() const = 0;
  31. #endif
  32. virtual size_t output_size() const = 0;
  33. protected:
  34. virtual ~PKSystem() = default;
  35. PublicKeyType m_public_key;
  36. PrivateKeyType m_private_key;
  37. };
  38. }
  39. }