mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibCrypto: Change the signatures of RSA::import_[XXX]_key to use Span.
This commit is contained in:
parent
3de4e08b46
commit
ed327e7feb
Notes:
sideshowbarker
2024-07-19 04:32:19 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/ed327e7feb3 Pull-request: https://github.com/SerenityOS/serenity/pull/2903
2 changed files with 21 additions and 13 deletions
|
@ -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();
|
||||
|
|
|
@ -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; }
|
||||
|
|
Loading…
Reference in a new issue