浏览代码

LibCrypto: Change the signature of RSA::parse_rsa_key to use Span.

asynts 5 年之前
父节点
当前提交
0d782e1dfb
共有 2 个文件被更改,包括 5 次插入4 次删除
  1. 3 3
      Libraries/LibCrypto/PK/RSA.cpp
  2. 2 1
      Libraries/LibCrypto/PK/RSA.h

+ 3 - 3
Libraries/LibCrypto/PK/RSA.cpp

@@ -33,7 +33,7 @@
 namespace Crypto {
 namespace Crypto {
 namespace PK {
 namespace PK {
 
 
-RSA::KeyPairType RSA::parse_rsa_key(const ByteBuffer& in)
+RSA::KeyPairType RSA::parse_rsa_key(ReadonlyBytes in)
 {
 {
     // we are going to assign to at least one of these
     // we are going to assign to at least one of these
     KeyPairType keypair;
     KeyPairType keypair;
@@ -167,7 +167,7 @@ void RSA::import_private_key(const ByteBuffer& buffer, bool pem)
 {
 {
     // so gods help me, I hate DER
     // so gods help me, I hate DER
     auto decoded_buffer = pem ? decode_pem(buffer) : buffer;
     auto decoded_buffer = pem ? decode_pem(buffer) : buffer;
-    auto key = parse_rsa_key(decoded_buffer);
+    auto key = parse_rsa_key(decoded_buffer.span());
     if (!key.private_key.length()) {
     if (!key.private_key.length()) {
         dbg() << "We expected to see a private key, but we found none";
         dbg() << "We expected to see a private key, but we found none";
         ASSERT_NOT_REACHED();
         ASSERT_NOT_REACHED();
@@ -179,7 +179,7 @@ void RSA::import_public_key(const ByteBuffer& buffer, bool pem)
 {
 {
     // so gods help me, I hate DER
     // so gods help me, I hate DER
     auto decoded_buffer = pem ? decode_pem(buffer) : buffer;
     auto decoded_buffer = pem ? decode_pem(buffer) : buffer;
-    auto key = parse_rsa_key(decoded_buffer);
+    auto key = parse_rsa_key(decoded_buffer.span());
     if (!key.public_key.length()) {
     if (!key.public_key.length()) {
         dbg() << "We expected to see a public key, but we found none";
         dbg() << "We expected to see a public key, but we found none";
         ASSERT_NOT_REACHED();
         ASSERT_NOT_REACHED();

+ 2 - 1
Libraries/LibCrypto/PK/RSA.h

@@ -26,6 +26,7 @@
 
 
 #pragma once
 #pragma once
 
 
+#include <AK/Span.h>
 #include <AK/Vector.h>
 #include <AK/Vector.h>
 #include <LibCrypto/BigInt/UnsignedBigInteger.h>
 #include <LibCrypto/BigInt/UnsignedBigInteger.h>
 #include <LibCrypto/NumberTheory/ModularFunctions.h>
 #include <LibCrypto/NumberTheory/ModularFunctions.h>
@@ -119,7 +120,7 @@ class RSA : public PKSystem<RSAPrivateKey<IntegerType>, RSAPublicKey<IntegerType
 public:
 public:
     using KeyPairType = RSAKeyPair<PublicKeyType, PrivateKeyType>;
     using KeyPairType = RSAKeyPair<PublicKeyType, PrivateKeyType>;
 
 
-    static KeyPairType parse_rsa_key(const ByteBuffer&);
+    static KeyPairType parse_rsa_key(ReadonlyBytes);
     static KeyPairType generate_key_pair(size_t bits = 256)
     static KeyPairType generate_key_pair(size_t bits = 256)
     {
     {
         IntegerType e { 65537 }; // :P
         IntegerType e { 65537 }; // :P