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