Code.h 749 B

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