|
1 | 1 | package ct |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bytes" |
5 | | - "container/list" |
6 | 4 | "crypto" |
7 | 5 | "encoding/binary" |
8 | 6 | "encoding/json" |
@@ -96,62 +94,6 @@ func readVarBytes(r io.Reader, numLenBytes int) ([]byte, error) { |
96 | 94 | return data, nil |
97 | 95 | } |
98 | 96 |
|
99 | | -// Reads a list of ASN1Cert types from |r| |
100 | | -func readASN1CertList(r io.Reader, totalLenBytes int, elementLenBytes int) ([]ASN1Cert, error) { |
101 | | - listBytes, err := readVarBytes(r, totalLenBytes) |
102 | | - if err != nil { |
103 | | - return []ASN1Cert{}, err |
104 | | - } |
105 | | - list := list.New() |
106 | | - listReader := bytes.NewReader(listBytes) |
107 | | - var entry []byte |
108 | | - for err == nil { |
109 | | - entry, err = readVarBytes(listReader, elementLenBytes) |
110 | | - if err != nil { |
111 | | - if err != io.EOF { |
112 | | - return []ASN1Cert{}, err |
113 | | - } |
114 | | - } else { |
115 | | - list.PushBack(entry) |
116 | | - } |
117 | | - } |
118 | | - ret := make([]ASN1Cert, list.Len()) |
119 | | - i := 0 |
120 | | - for e := list.Front(); e != nil; e = e.Next() { |
121 | | - ret[i] = ASN1Cert{Data: e.Value.([]byte)} |
122 | | - i++ |
123 | | - } |
124 | | - return ret, nil |
125 | | -} |
126 | | - |
127 | | -// UnmarshalX509ChainArray unmarshalls the contents of the "chain:" entry in a |
128 | | -// GetEntries response in the case where the entry refers to an X509 leaf. |
129 | | -func UnmarshalX509ChainArray(b []byte) ([]ASN1Cert, error) { |
130 | | - return readASN1CertList(bytes.NewReader(b), CertificateChainLengthBytes, CertificateLengthBytes) |
131 | | -} |
132 | | - |
133 | | -// UnmarshalPrecertChainArray unmarshalls the contents of the "chain:" entry in |
134 | | -// a GetEntries response in the case where the entry refers to a Precertificate |
135 | | -// leaf. |
136 | | -func UnmarshalPrecertChainArray(b []byte) ([]ASN1Cert, error) { |
137 | | - var chain []ASN1Cert |
138 | | - |
139 | | - reader := bytes.NewReader(b) |
140 | | - // read the pre-cert entry: |
141 | | - precert, err := readVarBytes(reader, CertificateLengthBytes) |
142 | | - if err != nil { |
143 | | - return chain, err |
144 | | - } |
145 | | - chain = append(chain, ASN1Cert{Data: precert}) |
146 | | - // and then read and return the chain up to the root: |
147 | | - remainingChain, err := readASN1CertList(reader, CertificateChainLengthBytes, CertificateLengthBytes) |
148 | | - if err != nil { |
149 | | - return chain, err |
150 | | - } |
151 | | - chain = append(chain, remainingChain...) |
152 | | - return chain, nil |
153 | | -} |
154 | | - |
155 | 97 | func checkExtensionsFormat(ext CTExtensions) error { |
156 | 98 | if len(ext) > MaxExtensionsLength { |
157 | 99 | return errors.New("extensions too large") |
|
0 commit comments