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

Side by Side Diff: mozilla/security/nss/lib/ckfw/builtins/bfind.c

Issue 14249009: Change the NSS and NSPR source tree to the new directory structure to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 8 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
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 #ifdef DEBUG
6 static const char CVS_ID[] = "@(#) $RCSfile: bfind.c,v $ $Revision: 1.7 $ $Date: 2012/04/25 14:49:29 $";
7 #endif /* DEBUG */
8
9 #ifndef BUILTINS_H
10 #include "builtins.h"
11 #endif /* BUILTINS_H */
12
13 /*
14 * builtins/find.c
15 *
16 * This file implements the NSSCKMDFindObjects object for the
17 * "builtin objects" cryptoki module.
18 */
19
20 struct builtinsFOStr {
21 NSSArena *arena;
22 CK_ULONG n;
23 CK_ULONG i;
24 builtinsInternalObject **objs;
25 };
26
27 static void
28 builtins_mdFindObjects_Final
29 (
30 NSSCKMDFindObjects *mdFindObjects,
31 NSSCKFWFindObjects *fwFindObjects,
32 NSSCKMDSession *mdSession,
33 NSSCKFWSession *fwSession,
34 NSSCKMDToken *mdToken,
35 NSSCKFWToken *fwToken,
36 NSSCKMDInstance *mdInstance,
37 NSSCKFWInstance *fwInstance
38 )
39 {
40 struct builtinsFOStr *fo = (struct builtinsFOStr *)mdFindObjects->etc;
41 NSSArena *arena = fo->arena;
42
43 nss_ZFreeIf(fo->objs);
44 nss_ZFreeIf(fo);
45 nss_ZFreeIf(mdFindObjects);
46 if ((NSSArena *)NULL != arena) {
47 NSSArena_Destroy(arena);
48 }
49
50 return;
51 }
52
53 static NSSCKMDObject *
54 builtins_mdFindObjects_Next
55 (
56 NSSCKMDFindObjects *mdFindObjects,
57 NSSCKFWFindObjects *fwFindObjects,
58 NSSCKMDSession *mdSession,
59 NSSCKFWSession *fwSession,
60 NSSCKMDToken *mdToken,
61 NSSCKFWToken *fwToken,
62 NSSCKMDInstance *mdInstance,
63 NSSCKFWInstance *fwInstance,
64 NSSArena *arena,
65 CK_RV *pError
66 )
67 {
68 struct builtinsFOStr *fo = (struct builtinsFOStr *)mdFindObjects->etc;
69 builtinsInternalObject *io;
70
71 if( fo->i == fo->n ) {
72 *pError = CKR_OK;
73 return (NSSCKMDObject *)NULL;
74 }
75
76 io = fo->objs[ fo->i ];
77 fo->i++;
78
79 return nss_builtins_CreateMDObject(arena, io, pError);
80 }
81
82 static int
83 builtins_derUnwrapInt(unsigned char *src, int size, unsigned char **dest) {
84 unsigned char *start = src;
85 int len = 0;
86
87 if (*src ++ != 2) {
88 return 0;
89 }
90 len = *src++;
91 if (len & 0x80) {
92 int count = len & 0x7f;
93 len =0;
94
95 if (count+2 > size) {
96 return 0;
97 }
98 while (count-- > 0) {
99 len = (len << 8) | *src++;
100 }
101 }
102 if (len + (src-start) != size) {
103 return 0;
104 }
105 *dest = src;
106 return len;
107 }
108
109 static CK_BBOOL
110 builtins_attrmatch
111 (
112 CK_ATTRIBUTE_PTR a,
113 const NSSItem *b
114 )
115 {
116 PRBool prb;
117
118 if( a->ulValueLen != b->size ) {
119 /* match a decoded serial number */
120 if ((a->type == CKA_SERIAL_NUMBER) && (a->ulValueLen < b->size)) {
121 int len;
122 unsigned char *data;
123
124 len = builtins_derUnwrapInt(b->data,b->size,&data);
125 if ((len == a->ulValueLen) &&
126 nsslibc_memequal(a->pValue, data, len, (PRStatus *)NULL)) {
127 return CK_TRUE;
128 }
129 }
130 return CK_FALSE;
131 }
132
133 prb = nsslibc_memequal(a->pValue, b->data, b->size, (PRStatus *)NULL);
134
135 if( PR_TRUE == prb ) {
136 return CK_TRUE;
137 } else {
138 return CK_FALSE;
139 }
140 }
141
142
143 static CK_BBOOL
144 builtins_match
145 (
146 CK_ATTRIBUTE_PTR pTemplate,
147 CK_ULONG ulAttributeCount,
148 builtinsInternalObject *o
149 )
150 {
151 CK_ULONG i;
152
153 for( i = 0; i < ulAttributeCount; i++ ) {
154 CK_ULONG j;
155
156 for( j = 0; j < o->n; j++ ) {
157 if( o->types[j] == pTemplate[i].type ) {
158 if( CK_FALSE == builtins_attrmatch(&pTemplate[i], &o->items[j]) ) {
159 return CK_FALSE;
160 } else {
161 break;
162 }
163 }
164 }
165
166 if( j == o->n ) {
167 /* Loop ran to the end: no matching attribute */
168 return CK_FALSE;
169 }
170 }
171
172 /* Every attribute passed */
173 return CK_TRUE;
174 }
175
176 NSS_IMPLEMENT NSSCKMDFindObjects *
177 nss_builtins_FindObjectsInit
178 (
179 NSSCKFWSession *fwSession,
180 CK_ATTRIBUTE_PTR pTemplate,
181 CK_ULONG ulAttributeCount,
182 CK_RV *pError
183 )
184 {
185 /* This could be made more efficient. I'm rather rushed. */
186 NSSArena *arena;
187 NSSCKMDFindObjects *rv = (NSSCKMDFindObjects *)NULL;
188 struct builtinsFOStr *fo = (struct builtinsFOStr *)NULL;
189 builtinsInternalObject **temp = (builtinsInternalObject **)NULL;
190 PRUint32 i;
191
192 arena = NSSArena_Create();
193 if( (NSSArena *)NULL == arena ) {
194 goto loser;
195 }
196
197 rv = nss_ZNEW(arena, NSSCKMDFindObjects);
198 if( (NSSCKMDFindObjects *)NULL == rv ) {
199 *pError = CKR_HOST_MEMORY;
200 goto loser;
201 }
202
203 fo = nss_ZNEW(arena, struct builtinsFOStr);
204 if( (struct builtinsFOStr *)NULL == fo ) {
205 *pError = CKR_HOST_MEMORY;
206 goto loser;
207 }
208
209 fo->arena = arena;
210 /* fo->n and fo->i are already zero */
211
212 rv->etc = (void *)fo;
213 rv->Final = builtins_mdFindObjects_Final;
214 rv->Next = builtins_mdFindObjects_Next;
215 rv->null = (void *)NULL;
216
217 temp = nss_ZNEWARRAY((NSSArena *)NULL, builtinsInternalObject *,
218 nss_builtins_nObjects);
219 if( (builtinsInternalObject **)NULL == temp ) {
220 *pError = CKR_HOST_MEMORY;
221 goto loser;
222 }
223
224 for( i = 0; i < nss_builtins_nObjects; i++ ) {
225 builtinsInternalObject *o = (builtinsInternalObject *)&nss_builtins_data[i];
226
227 if( CK_TRUE == builtins_match(pTemplate, ulAttributeCount, o) ) {
228 temp[ fo->n ] = o;
229 fo->n++;
230 }
231 }
232
233 fo->objs = nss_ZNEWARRAY(arena, builtinsInternalObject *, fo->n);
234 if( (builtinsInternalObject **)NULL == fo->objs ) {
235 *pError = CKR_HOST_MEMORY;
236 goto loser;
237 }
238
239 (void)nsslibc_memcpy(fo->objs, temp, sizeof(builtinsInternalObject *) * fo->n) ;
240 nss_ZFreeIf(temp);
241 temp = (builtinsInternalObject **)NULL;
242
243 return rv;
244
245 loser:
246 nss_ZFreeIf(temp);
247 nss_ZFreeIf(fo);
248 nss_ZFreeIf(rv);
249 if ((NSSArena *)NULL != arena) {
250 NSSArena_Destroy(arena);
251 }
252 return (NSSCKMDFindObjects *)NULL;
253 }
254
OLDNEW
« no previous file with comments | « mozilla/security/nss/lib/ckfw/builtins/anchor.c ('k') | mozilla/security/nss/lib/ckfw/builtins/binst.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698