diff options
author | asynts <asynts@gmail.com> | 2020-07-27 15:28:38 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-27 19:58:09 +0200 |
commit | ed327e7feb36d415281ad022d6f99a9d15539e6a (patch) | |
tree | 25781e990328f11b6152808e5a2640910c63c825 /Libraries | |
parent | 3de4e08b465514dd978e4a3c80c9fd0e9e414c7b (diff) | |
download | serenity-ed327e7feb36d415281ad022d6f99a9d15539e6a.zip |
LibCrypto: Change the signatures of RSA::import_[XXX]_key to use Span.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibCrypto/PK/RSA.cpp | 24 | ||||
-rw-r--r-- | Libraries/LibCrypto/PK/RSA.h | 10 |
2 files changed, 21 insertions, 13 deletions
diff --git a/Libraries/LibCrypto/PK/RSA.cpp b/Libraries/LibCrypto/PK/RSA.cpp index 5e0f12cba7..1c984c60c2 100644 --- a/Libraries/LibCrypto/PK/RSA.cpp +++ b/Libraries/LibCrypto/PK/RSA.cpp @@ -163,11 +163,15 @@ void RSA::verify(const ByteBuffer& in, ByteBuffer& out) out = out.slice(out.size() - size, size); } -void RSA::import_private_key(const ByteBuffer& buffer, bool pem) +void RSA::import_private_key(ReadonlyBytes bytes, bool pem) { - // so gods help me, I hate DER - auto decoded_buffer = pem ? decode_pem(buffer.span()) : buffer; - auto key = parse_rsa_key(decoded_buffer.span()); + ByteBuffer buffer; + if (pem) { + buffer = decode_pem(bytes); + bytes = buffer.span(); + } + + auto key = parse_rsa_key(bytes); if (!key.private_key.length()) { dbg() << "We expected to see a private key, but we found none"; ASSERT_NOT_REACHED(); @@ -175,11 +179,15 @@ void RSA::import_private_key(const ByteBuffer& buffer, bool pem) m_private_key = key.private_key; } -void RSA::import_public_key(const ByteBuffer& buffer, bool pem) +void RSA::import_public_key(ReadonlyBytes bytes, bool pem) { - // so gods help me, I hate DER - auto decoded_buffer = pem ? decode_pem(buffer.span()) : buffer; - auto key = parse_rsa_key(decoded_buffer.span()); + ByteBuffer buffer; + if (pem) { + buffer = decode_pem(bytes); + bytes = buffer.span(); + } + + auto key = parse_rsa_key(bytes); if (!key.public_key.length()) { dbg() << "We expected to see a public key, but we found none"; ASSERT_NOT_REACHED(); diff --git a/Libraries/LibCrypto/PK/RSA.h b/Libraries/LibCrypto/PK/RSA.h index 6a5f56ad1b..9d429d0b4a 100644 --- a/Libraries/LibCrypto/PK/RSA.h +++ b/Libraries/LibCrypto/PK/RSA.h @@ -160,13 +160,13 @@ public: RSA(const ByteBuffer& publicKeyPEM, const ByteBuffer& privateKeyPEM) { - import_public_key(publicKeyPEM); - import_private_key(privateKeyPEM); + import_public_key(publicKeyPEM.span()); + import_private_key(privateKeyPEM.span()); } RSA(const StringView& privKeyPEM) { - import_private_key(ByteBuffer::wrap(privKeyPEM.characters_without_null_termination(), privKeyPEM.length())); + import_private_key(privKeyPEM.bytes()); m_public_key.set(m_private_key.modulus(), m_private_key.public_exponent()); } @@ -188,8 +188,8 @@ public: virtual size_t output_size() const override { return m_public_key.length(); } - void import_public_key(const ByteBuffer& buffer, bool pem = true); - void import_private_key(const ByteBuffer& buffer, bool pem = true); + void import_public_key(ReadonlyBytes, bool pem = true); + void import_private_key(ReadonlyBytes, bool pem = true); const PrivateKeyType& private_key() const { return m_private_key; } const PublicKeyType& public_key() const { return m_public_key; } |