From eecbdf806281450352a989b0093100b0b9c15c35 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Fri, 15 Nov 2024 08:47:27 -0700 Subject: [PATCH] Simplify SubjectPublicKeyInfo validation to reduce code bloat. --- services/system/AuthSig/src/Spki.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/services/system/AuthSig/src/Spki.cpp b/services/system/AuthSig/src/Spki.cpp index 44dc3115b..6591de18e 100644 --- a/services/system/AuthSig/src/Spki.cpp +++ b/services/system/AuthSig/src/Spki.cpp @@ -12,7 +12,14 @@ namespace SystemService { bool SubjectPublicKeyInfo::validate(const std::vector& data) { - Botan::X509::load_key({data.data(), data.size()}); // Throws if decoding fails + Botan::AlgorithmIdentifier algorithm; + std::vector key; + + Botan::BER_Decoder(data) + .start_sequence() + .decode(algorithm) + .decode(key, Botan::ASN1_Type::BitString) + .end_cons(); return true; } @@ -29,12 +36,9 @@ namespace SystemService "Pem->SPKI: Expected label \"PUBLIC KEY\", got label: " + label_got); } - Botan::BER_Decoder(ber) - .start_sequence() - .decode(algorithm) - .decode(key, Botan::ASN1_Type::BitString) - .end_cons(); - return std::vector(ber.begin(), ber.end()); + auto result = std::vector(ber.begin(), ber.end()); + SubjectPublicKeyInfo::validate(result); + return result; } std::vector parseSubjectPublicKeyInfo(std::string_view s) @@ -73,4 +77,4 @@ namespace SystemService return result; } } // namespace AuthSig -} // namespace SystemService \ No newline at end of file +} // namespace SystemService