2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Netscape security libraries.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1994-2000 Netscape Communications Corporation. All
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU General Public License Version 2 or later (the
23 * "GPL"), in which case the provisions of the GPL are applicable
24 * instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the GPL and not to
26 * allow others to use your version of this file under the MPL,
27 * indicate your decision by deleting the provisions above and
28 * replace them with the notice and other provisions required by
29 * the GPL. If you do not delete the provisions above, a recipient
30 * may use your version of this file under either the MPL or the
35 #include "SecAsn1Item.h"
36 #include <security_asn1/secasn1.h>
37 #include <security_asn1/secerr.h>
38 #include <security_asn1/secport.h>
40 const SecAsn1Template SECOID_AlgorithmIDTemplate
[] = {
42 0, NULL
, sizeof(SECAlgorithmID
) },
44 offsetof(SECAlgorithmID
,algorithm
), },
45 { SEC_ASN1_OPTIONAL
| SEC_ASN1_ANY
,
46 offsetof(SECAlgorithmID
,parameters
), },
51 SECOID_GetAlgorithmTag(const SECAlgorithmID
*id
)
53 if (id
== NULL
|| id
->algorithm
.Data
== NULL
)
54 return SEC_OID_UNKNOWN
;
56 return SECOID_FindOIDTag (&(id
->algorithm
));
60 SECOID_SetAlgorithmID(PRArenaPool
*arena
, SECAlgorithmID
*id
, SECOidTag which
,
61 const SecAsn1Item
*params
)
64 Boolean add_null_param
;
66 oiddata
= SECOID_FindOIDByTag(which
);
69 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM
);
73 if (SECITEM_CopyItem(arena
, &id
->algorithm
, &oiddata
->oid
))
85 case SEC_OID_PKCS1_RSA_ENCRYPTION
:
86 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION
:
87 case SEC_OID_PKCS1_MD4_WITH_RSA_ENCRYPTION
:
88 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION
:
89 case SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION
:
90 case SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION
:
91 case SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION
:
92 case SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION
:
93 add_null_param
= PR_TRUE
;
96 add_null_param
= PR_FALSE
;
102 * I am specifically *not* enforcing the following assertion
103 * (by following it up with an error and a return of failure)
104 * because I do not want to introduce any change in the current
105 * behavior. But I do want for us to notice if the following is
106 * ever true, because I do not think it should be so and probably
107 * signifies an error/bug somewhere.
109 PORT_Assert(!add_null_param
|| (params
->Length
== 2
110 && params
->Data
[0] == SEC_ASN1_NULL
111 && params
->Data
[1] == 0));
112 if (SECITEM_CopyItem(arena
, &id
->parameters
, params
)) {
117 * Again, this is not considered an error. But if we assume
118 * that nobody tries to set the parameters field themselves
119 * (but always uses this routine to do that), then we should
120 * not hit the following assertion. Unless they forgot to zero
121 * the structure, which could also be a bad (and wrong) thing.
123 PORT_Assert(id
->parameters
.Data
== NULL
);
125 if (add_null_param
) {
126 (void) SECITEM_AllocItem(arena
, &id
->parameters
, 2);
127 if (id
->parameters
.Data
== NULL
) {
130 id
->parameters
.Data
[0] = SEC_ASN1_NULL
;
131 id
->parameters
.Data
[1] = 0;
139 SECOID_CopyAlgorithmID(PRArenaPool
*arena
, SECAlgorithmID
*to
, const SECAlgorithmID
*from
)
143 rv
= SECITEM_CopyItem(arena
, &to
->algorithm
, &from
->algorithm
);
145 rv
= SECITEM_CopyItem(arena
, &to
->parameters
, &from
->parameters
);
149 void SECOID_DestroyAlgorithmID(SECAlgorithmID
*algid
, Boolean freeit
)
151 SECITEM_FreeItem(&algid
->parameters
, PR_FALSE
);
152 SECITEM_FreeItem(&algid
->algorithm
, PR_FALSE
);
153 if(freeit
== PR_TRUE
)
158 SECOID_CompareAlgorithmID(const SECAlgorithmID
*a
, const SECAlgorithmID
*b
)
162 rv
= SECITEM_CompareItem(&a
->algorithm
, &b
->algorithm
);
164 rv
= SECITEM_CompareItem(&a
->parameters
, &b
->parameters
);
168 /* This functions simply returns the address of the above-declared template. */
169 SEC_ASN1_CHOOSER_IMPLEMENT(SECOID_AlgorithmIDTemplate
)