Code.h 762 B

12345678910111213141516171819202122232425262728293031323334353637
  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 <LibCrypto/Hash/HashFunction.h>
  8. #include <LibCrypto/Verification.h>
  9. namespace Crypto {
  10. namespace PK {
  11. template<typename HashFunction>
  12. class Code {
  13. public:
  14. template<typename... Args>
  15. Code(Args... args)
  16. : m_hasher(args...)
  17. {
  18. }
  19. virtual void encode(ReadonlyBytes in, ByteBuffer& out, size_t em_bits) = 0;
  20. virtual VerificationConsistency verify(ReadonlyBytes msg, ReadonlyBytes emsg, size_t em_bits) = 0;
  21. HashFunction const& hasher() const { return m_hasher; }
  22. HashFunction& hasher() { return m_hasher; }
  23. protected:
  24. virtual ~Code() = default;
  25. HashFunction m_hasher;
  26. };
  27. }
  28. }