OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 #include "secder.h" | 5 #include "secder.h" |
6 #include <limits.h> | 6 #include <limits.h> |
7 #include "secerr.h" | 7 #include "secerr.h" |
8 | 8 |
9 int | 9 int |
10 DER_LengthLength(PRUint32 len) | 10 DER_LengthLength(PRUint32 len) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 PORT_Memcpy(it->data, bb + (sizeof(bb) - len), len); | 169 PORT_Memcpy(it->data, bb + (sizeof(bb) - len), len); |
170 | 170 |
171 return SECSuccess; | 171 return SECSuccess; |
172 } | 172 } |
173 | 173 |
174 /* | 174 /* |
175 ** Convert a der encoded *signed* integer into a machine integral value. | 175 ** Convert a der encoded *signed* integer into a machine integral value. |
176 ** If an underflow/overflow occurs, sets error code and returns min/max. | 176 ** If an underflow/overflow occurs, sets error code and returns min/max. |
177 */ | 177 */ |
178 long | 178 long |
179 DER_GetInteger(SECItem *it) | 179 DER_GetInteger(const SECItem *it) |
180 { | 180 { |
181 long ival = 0; | 181 long ival = 0; |
182 unsigned len = it->len; | 182 unsigned len = it->len; |
183 unsigned char *cp = it->data; | 183 unsigned char *cp = it->data; |
184 unsigned long overflow = 0x1ffUL << (((sizeof(ival) - 1) * 8) - 1); | 184 unsigned long overflow = 0x1ffUL << (((sizeof(ival) - 1) * 8) - 1); |
185 unsigned long ofloinit; | 185 unsigned long ofloinit; |
186 | 186 |
187 PORT_Assert(len); | 187 PORT_Assert(len); |
188 if (!len) { | 188 if (!len) { |
189 PORT_SetError(SEC_ERROR_INPUT_LEN); | 189 PORT_SetError(SEC_ERROR_INPUT_LEN); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (ival & overflow) { | 237 if (ival & overflow) { |
238 PORT_SetError(SEC_ERROR_BAD_DER); | 238 PORT_SetError(SEC_ERROR_BAD_DER); |
239 return ULONG_MAX; | 239 return ULONG_MAX; |
240 } | 240 } |
241 ival = ival << 8; | 241 ival = ival << 8; |
242 ival |= *cp++; | 242 ival |= *cp++; |
243 --len; | 243 --len; |
244 } | 244 } |
245 return ival; | 245 return ival; |
246 } | 246 } |
OLD | NEW |