Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
5 #include "secplcy.h"
6 #include "prmem.h"
8 SECCipherFind *sec_CipherFindInit(PRBool onlyAllowed,
9 secCPStruct *policy,
10 long *ciphers)
11 {
12 SECCipherFind *find = PR_NEWZAP(SECCipherFind);
13 if (find)
14 {
15 find->policy = policy;
16 find->ciphers = ciphers;
17 find->onlyAllowed = onlyAllowed;
18 find->index = -1;
19 }
20 return find;
21 }
23 long sec_CipherFindNext(SECCipherFind *find)
24 {
25 char *policy;
26 long rv = -1;
27 secCPStruct *policies = (secCPStruct *) find->policy;
28 long *ciphers = (long *) find->ciphers;
29 long numCiphers = policies->num_ciphers;
31 find->index++;
32 while((find->index < numCiphers) && (rv == -1))
33 {
34 /* Translate index to cipher. */
35 rv = ciphers[find->index];
37 /* If we're only looking for allowed ciphers, and if this
38 cipher isn't allowed, loop around.*/
39 if (find->onlyAllowed)
40 {
41 /* Find the appropriate policy flag. */
42 policy = (&(policies->begin_ciphers)) + find->index + 1;
44 /* If this cipher isn't allowed by policy, continue. */
45 if (! (*policy))
46 {
47 rv = -1;
48 find->index++;
49 }
50 }
51 }
53 return rv;
54 }
56 char sec_IsCipherAllowed(long cipher, secCPStruct *policies,
57 long *ciphers)
58 {
59 char result = SEC_CIPHER_NOT_ALLOWED; /* our default answer */
60 long numCiphers = policies->num_ciphers;
61 char *policy;
62 int i;
64 /* Convert the cipher number into a policy flag location. */
65 for (i=0, policy=(&(policies->begin_ciphers) + 1);
66 i<numCiphers;
67 i++, policy++)
68 {
69 if (cipher == ciphers[i])
70 break;
71 }
73 if (i < numCiphers)
74 {
75 /* Found the cipher, get the policy value. */
76 result = *policy;
77 }
79 return result;
80 }
82 void sec_CipherFindEnd(SECCipherFind *find)
83 {
84 PR_FREEIF(find);
85 }