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

Unified Diff: net/cert/internal/signature_algorithm.cc

Issue 1541213002: Adding OCSP Parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix more null checks. Created 4 years, 9 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/cert/internal/signature_algorithm.h ('k') | net/data/parse_ocsp_unittest/annotate_test_data.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/internal/signature_algorithm.cc
diff --git a/net/cert/internal/signature_algorithm.cc b/net/cert/internal/signature_algorithm.cc
index 13243ea428798b509d3d804c4308147565d4a935..315243f3968ebe9378ef585af770e841ea02dcd7 100644
--- a/net/cert/internal/signature_algorithm.cc
+++ b/net/cert/internal/signature_algorithm.cc
@@ -321,49 +321,6 @@ scoped_ptr<SignatureAlgorithm> ParseEcdsa(DigestAlgorithm digest,
return SignatureAlgorithm::CreateEcdsa(digest);
}
-// Parses a HashAlgorithm as defined by RFC 5912:
-//
-// HashAlgorithm ::= AlgorithmIdentifier{DIGEST-ALGORITHM,
-// {HashAlgorithms}}
-//
-// HashAlgorithms DIGEST-ALGORITHM ::= {
-// { IDENTIFIER id-sha1 PARAMS TYPE NULL ARE preferredPresent } |
-// { IDENTIFIER id-sha224 PARAMS TYPE NULL ARE preferredPresent } |
-// { IDENTIFIER id-sha256 PARAMS TYPE NULL ARE preferredPresent } |
-// { IDENTIFIER id-sha384 PARAMS TYPE NULL ARE preferredPresent } |
-// { IDENTIFIER id-sha512 PARAMS TYPE NULL ARE preferredPresent }
-// }
-WARN_UNUSED_RESULT bool ParseHashAlgorithm(const der::Input input,
- DigestAlgorithm* out) {
- der::Input oid;
- der::Input params;
- if (!ParseAlgorithmIdentifier(input, &oid, &params))
- return false;
-
- DigestAlgorithm hash;
-
- if (oid == der::Input(kOidSha1)) {
- hash = DigestAlgorithm::Sha1;
- } else if (oid == der::Input(kOidSha256)) {
- hash = DigestAlgorithm::Sha256;
- } else if (oid == der::Input(kOidSha384)) {
- hash = DigestAlgorithm::Sha384;
- } else if (oid == der::Input(kOidSha512)) {
- hash = DigestAlgorithm::Sha512;
- } else {
- // Unsupported digest algorithm.
- return false;
- }
-
- // From RFC 5912: "PARAMS TYPE NULL ARE preferredPresent". Which is to say
- // the can either be absent, or NULL.
- if (!IsEmpty(params) && !IsNull(params))
- return false;
-
- *out = hash;
- return true;
-}
-
// Parses a MaskGenAlgorithm as defined by RFC 5912:
//
// MaskGenAlgorithm ::= AlgorithmIdentifier{ALGORITHM,
@@ -539,6 +496,37 @@ scoped_ptr<SignatureAlgorithm> ParseRsaPss(const der::Input& params) {
} // namespace
+WARN_UNUSED_RESULT bool ParseHashAlgorithm(const der::Input input,
+ DigestAlgorithm* out) {
+ der::Input oid;
+ der::Input params;
+ if (!ParseAlgorithmIdentifier(input, &oid, &params))
+ return false;
+
+ DigestAlgorithm hash;
+
+ if (oid == der::Input(kOidSha1)) {
+ hash = DigestAlgorithm::Sha1;
+ } else if (oid == der::Input(kOidSha256)) {
+ hash = DigestAlgorithm::Sha256;
+ } else if (oid == der::Input(kOidSha384)) {
+ hash = DigestAlgorithm::Sha384;
+ } else if (oid == der::Input(kOidSha512)) {
+ hash = DigestAlgorithm::Sha512;
+ } else {
+ // Unsupported digest algorithm.
+ return false;
+ }
+
+ // From RFC 5912: "PARAMS TYPE NULL ARE preferredPresent". Which is to say
+ // the can either be absent, or NULL.
+ if (!IsEmpty(params) && !IsNull(params))
+ return false;
+
+ *out = hash;
+ return true;
+}
+
RsaPssParameters::RsaPssParameters(DigestAlgorithm mgf1_hash,
uint32_t salt_length)
: mgf1_hash_(mgf1_hash), salt_length_(salt_length) {
« no previous file with comments | « net/cert/internal/signature_algorithm.h ('k') | net/data/parse_ocsp_unittest/annotate_test_data.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698