Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1743)

Unified Diff: net/base/asn1_util.cc

Issue 10821111: Add a new ExtractSubjectPublicKeyFromSPKI method to asn1_utils. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/asn1_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/asn1_util.cc
diff --git a/net/base/asn1_util.cc b/net/base/asn1_util.cc
index a1e8637f8706a95f0aacdc8ad295e6f785322952..833ec1a1bec48bf8aff77c32208a5b1a82777a08 100644
--- a/net/base/asn1_util.cc
+++ b/net/base/asn1_util.cc
@@ -157,6 +157,34 @@ bool ExtractSPKIFromDERCert(base::StringPiece cert,
return true;
}
+bool ExtractSubjectPublicKeyFromSPKI(base::StringPiece spki,
+ base::StringPiece* spk_out) {
+ // From RFC 5280, Section 4.1
+ // SubjectPublicKeyInfo ::= SEQUENCE {
+ // algorithm AlgorithmIdentifier,
+ // subjectPublicKey BIT STRING }
+ //
+ // AlgorithmIdentifier ::= SEQUENCE {
+ // algorithm OBJECT IDENTIFIER,
+ // parameters ANY DEFINED BY algorithm OPTIONAL }
+
+ // Step into SubjectPublicKeyInfo sequence.
+ base::StringPiece spki_contents;
+ if (!asn1::GetElement(&spki, asn1::kSEQUENCE, &spki_contents))
+ return false;
+
+ // Step over algorithm field (a SEQUENCE).
+ base::StringPiece algorithm;
+ if (!asn1::GetElement(&spki_contents, asn1::kSEQUENCE, &algorithm))
+ return false;
+
+ // Extract the subjectPublicKey field.
+ if (!asn1::GetElement(&spki_contents, asn1::kBITSTRING, spk_out))
+ return false;
+ return true;
+}
+
+
bool ExtractCRLURLsFromDERCert(base::StringPiece cert,
std::vector<base::StringPiece>* urls_out) {
urls_out->clear();
« no previous file with comments | « net/base/asn1_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698