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

Side by Side Diff: net/base/asn1_util.h

Issue 6993027: net: followup to codereview for cl/7096014 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/asn1_util.cc » ('j') | net/base/asn1_util.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_BASE_ASN1_UTIL_H_ 5 #ifndef NET_BASE_ASN1_UTIL_H_
6 #define NET_BASE_ASN1_UTIL_H_ 6 #define NET_BASE_ASN1_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/string_piece.h" 11 #include "base/string_piece.h"
12 #include "net/base/net_api.h" 12 #include "net/base/net_api.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 namespace asn1 { 16 namespace asn1 {
17 17
18 // These are the DER encodings of the tag byte for ASN.1 objects. 18 // These are the DER encodings of the tag byte for ASN.1 objects.
19 static const unsigned kBOOLEAN = 0x01; 19 static const unsigned kBOOLEAN = 0x01;
20 static const unsigned kINTEGER = 0x02; 20 static const unsigned kINTEGER = 0x02;
21 static const unsigned kOCTETSTRING = 0x04; 21 static const unsigned kOCTETSTRING = 0x04;
22 static const unsigned kOID = 0x06; 22 static const unsigned kOID = 0x06;
23 static const unsigned kSEQUENCE = 0x30; 23 static const unsigned kSEQUENCE = 0x30;
24 24
25 // These are flags that can be ORed with the above tag numbers. 25 // These are flags that can be ORed with the above tag numbers.
26 static const unsigned kContextSpecific = 0x80; 26 static const unsigned kContextSpecific = 0x80;
27 static const unsigned kCompound = 0x20; 27 static const unsigned kConstructed = 0x20;
28 28
29 // kAny matches any tag value; 29 // kAny matches any tag value;
30 static const unsigned kAny = 0x10000; 30 static const unsigned kAny = 0x10000;
31 // kOptional denotes an optional element.
32 static const unsigned kOptional = 0x20000;
31 33
32 // ParseElement parses a DER encoded ASN1 element from |in|, requiring that 34 // ParseElement parses a DER encoded ASN1 element from |in|, requiring that
33 // it have the given |tag_value|. It returns true on success. The following 35 // it have the given |tag_value|. It returns true on success. The following
34 // limitations are imposed: 36 // limitations are imposed:
35 // 1) tag numbers > 31 are not permitted. 37 // 1) tag numbers > 31 are not permitted.
36 // 2) lengths > 65535 are not permitted. 38 // 2) lengths > 65535 are not permitted.
37 // On successful return: 39 // On successful return:
38 // |in| is advanced over the element 40 // |in| is advanced over the element
39 // |out| contains the element, including the tag and length bytes. 41 // |out| contains the element, including the tag and length bytes.
40 // |out_header_len| contains the length of the tag and length bytes in |out|. 42 // |out_header_len| contains the length of the tag and length bytes in |out|.
43 //
44 // If |tag_value & kOptional| is true then *out_header_len can be zero after a
45 // true return value if the element was not found.
wtc 2011/06/07 18:17:54 I think this will allow us to distinguish between
41 bool ParseElement(base::StringPiece* in, 46 bool ParseElement(base::StringPiece* in,
42 unsigned tag_value, 47 unsigned tag_value,
43 base::StringPiece* out, 48 base::StringPiece* out,
44 unsigned *out_header_len); 49 unsigned *out_header_len);
45 50
46 // GetElement performs the same actions as ParseElement, except that the header 51 // GetElement performs the same actions as ParseElement, except that the header
47 // bytes are not included in the output. 52 // bytes are not included in the output.
53 //
54 // If |tag_value & kOptional| is true then this function cannot distinguish
55 // between a missing optional element and an empty one.
48 bool GetElement(base::StringPiece* in, 56 bool GetElement(base::StringPiece* in,
49 unsigned tag_value, 57 unsigned tag_value,
50 base::StringPiece* out); 58 base::StringPiece* out);
51 59
52
53 // ExtractSPKIFromDERCert parses the DER encoded certificate in |cert| and 60 // ExtractSPKIFromDERCert parses the DER encoded certificate in |cert| and
54 // extracts the bytes of the SubjectPublicKeyInfo. On successful return, 61 // extracts the bytes of the SubjectPublicKeyInfo. On successful return,
55 // |spki_out| is set to contain the SPKI, pointing into |cert|. 62 // |spki_out| is set to contain the SPKI, pointing into |cert|.
56 NET_TEST bool ExtractSPKIFromDERCert(base::StringPiece cert, 63 NET_TEST bool ExtractSPKIFromDERCert(base::StringPiece cert,
57 base::StringPiece* spki_out); 64 base::StringPiece* spki_out);
58 65
59 // ExtractCRLURLsFromDERCert parses the DER encoded certificate in |cert| and 66 // ExtractCRLURLsFromDERCert parses the DER encoded certificate in |cert| and
60 // extracts the URL of each CRL. On successful return, the elements of 67 // extracts the URL of each CRL. On successful return, the elements of
61 // |urls_out| point into |cert|. 68 // |urls_out| point into |cert|.
62 // 69 //
63 // CRLs that only cover a subset of the reasons are omitted as the spec 70 // CRLs that only cover a subset of the reasons are omitted as the spec
64 // requires that at least one CRL be included that covers all reasons. 71 // requires that at least one CRL be included that covers all reasons.
65 // 72 //
73 // CRLs that use an alternative issuer are also omitted.
74 //
66 // The nested set of GeneralNames is flattened into a single list because 75 // The nested set of GeneralNames is flattened into a single list because
67 // having several CRLs with one location is equivalent to having one CRL with 76 // having several CRLs with one location is equivalent to having one CRL with
68 // several locations as far as a CRL filter is concerned. 77 // several locations as far as a CRL filter is concerned.
69 bool ExtractCRLURLsFromDERCert(base::StringPiece cert, 78 bool ExtractCRLURLsFromDERCert(base::StringPiece cert,
70 std::vector<base::StringPiece>* urls_out); 79 std::vector<base::StringPiece>* urls_out);
71 80
72 } // namespace asn1 81 } // namespace asn1
73 82
74 } // namespace net 83 } // namespace net
75 84
76 #endif // NET_BASE_ASN1_UTIL_H_ 85 #endif // NET_BASE_ASN1_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/asn1_util.cc » ('j') | net/base/asn1_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698