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

Side by Side Diff: nss/lib/util/secalgid.c

Issue 2078763002: Delete bundled copy of NSS and replace with README. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss@master
Patch Set: Delete bundled copy of NSS and replace with README. Created 4 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
« no previous file with comments | « nss/lib/util/quickder.c ('k') | nss/lib/util/secasn1.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include "secoid.h"
6 #include "secder.h" /* XXX remove this when remove the DERTemplate */
7 #include "secasn1.h"
8 #include "secitem.h"
9 #include "secerr.h"
10
11 SECOidTag
12 SECOID_GetAlgorithmTag(const SECAlgorithmID *id)
13 {
14 if (id == NULL || id->algorithm.data == NULL)
15 return SEC_OID_UNKNOWN;
16
17 return SECOID_FindOIDTag (&(id->algorithm));
18 }
19
20 SECStatus
21 SECOID_SetAlgorithmID(PLArenaPool *arena, SECAlgorithmID *id, SECOidTag which,
22 SECItem *params)
23 {
24 SECOidData *oiddata;
25 PRBool add_null_param;
26
27 oiddata = SECOID_FindOIDByTag(which);
28 if ( !oiddata ) {
29 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM);
30 return SECFailure;
31 }
32
33 if (SECITEM_CopyItem(arena, &id->algorithm, &oiddata->oid))
34 return SECFailure;
35
36 switch (which) {
37 case SEC_OID_MD2:
38 case SEC_OID_MD4:
39 case SEC_OID_MD5:
40 case SEC_OID_SHA1:
41 case SEC_OID_SHA224:
42 case SEC_OID_SHA256:
43 case SEC_OID_SHA384:
44 case SEC_OID_SHA512:
45 case SEC_OID_PKCS1_RSA_ENCRYPTION:
46 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION:
47 case SEC_OID_PKCS1_MD4_WITH_RSA_ENCRYPTION:
48 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION:
49 case SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION:
50 case SEC_OID_PKCS1_SHA224_WITH_RSA_ENCRYPTION:
51 case SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION:
52 case SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION:
53 case SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION:
54 add_null_param = PR_TRUE;
55 break;
56 default:
57 add_null_param = PR_FALSE;
58 break;
59 }
60
61 if (params) {
62 /*
63 * I am specifically *not* enforcing the following assertion
64 * (by following it up with an error and a return of failure)
65 * because I do not want to introduce any change in the current
66 * behavior. But I do want for us to notice if the following is
67 * ever true, because I do not think it should be so and probably
68 * signifies an error/bug somewhere.
69 */
70 PORT_Assert(!add_null_param || (params->len == 2
71 && params->data[0] == SEC_ASN1_NULL
72 && params->data[1] == 0));
73 if (SECITEM_CopyItem(arena, &id->parameters, params)) {
74 return SECFailure;
75 }
76 } else {
77 /*
78 * Again, this is not considered an error. But if we assume
79 * that nobody tries to set the parameters field themselves
80 * (but always uses this routine to do that), then we should
81 * not hit the following assertion. Unless they forgot to zero
82 * the structure, which could also be a bad (and wrong) thing.
83 */
84 PORT_Assert(id->parameters.data == NULL);
85
86 if (add_null_param) {
87 (void) SECITEM_AllocItem(arena, &id->parameters, 2);
88 if (id->parameters.data == NULL) {
89 return SECFailure;
90 }
91 id->parameters.data[0] = SEC_ASN1_NULL;
92 id->parameters.data[1] = 0;
93 }
94 }
95
96 return SECSuccess;
97 }
98
99 SECStatus
100 SECOID_CopyAlgorithmID(PLArenaPool *arena, SECAlgorithmID *to,
101 const SECAlgorithmID *from)
102 {
103 SECStatus rv;
104
105 rv = SECITEM_CopyItem(arena, &to->algorithm, &from->algorithm);
106 if (rv) return rv;
107 rv = SECITEM_CopyItem(arena, &to->parameters, &from->parameters);
108 return rv;
109 }
110
111 void SECOID_DestroyAlgorithmID(SECAlgorithmID *algid, PRBool freeit)
112 {
113 SECITEM_FreeItem(&algid->parameters, PR_FALSE);
114 SECITEM_FreeItem(&algid->algorithm, PR_FALSE);
115 if(freeit == PR_TRUE)
116 PORT_Free(algid);
117 }
118
119 SECComparison
120 SECOID_CompareAlgorithmID(SECAlgorithmID *a, SECAlgorithmID *b)
121 {
122 SECComparison rv;
123
124 rv = SECITEM_CompareItem(&a->algorithm, &b->algorithm);
125 if (rv) return rv;
126 rv = SECITEM_CompareItem(&a->parameters, &b->parameters);
127 return rv;
128 }
OLDNEW
« no previous file with comments | « nss/lib/util/quickder.c ('k') | nss/lib/util/secasn1.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698