1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/util/secplcy.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "secplcy.h" 1.9 +#include "prmem.h" 1.10 + 1.11 +SECCipherFind *sec_CipherFindInit(PRBool onlyAllowed, 1.12 + secCPStruct *policy, 1.13 + long *ciphers) 1.14 +{ 1.15 + SECCipherFind *find = PR_NEWZAP(SECCipherFind); 1.16 + if (find) 1.17 + { 1.18 + find->policy = policy; 1.19 + find->ciphers = ciphers; 1.20 + find->onlyAllowed = onlyAllowed; 1.21 + find->index = -1; 1.22 + } 1.23 + return find; 1.24 +} 1.25 + 1.26 +long sec_CipherFindNext(SECCipherFind *find) 1.27 +{ 1.28 + char *policy; 1.29 + long rv = -1; 1.30 + secCPStruct *policies = (secCPStruct *) find->policy; 1.31 + long *ciphers = (long *) find->ciphers; 1.32 + long numCiphers = policies->num_ciphers; 1.33 + 1.34 + find->index++; 1.35 + while((find->index < numCiphers) && (rv == -1)) 1.36 + { 1.37 + /* Translate index to cipher. */ 1.38 + rv = ciphers[find->index]; 1.39 + 1.40 + /* If we're only looking for allowed ciphers, and if this 1.41 + cipher isn't allowed, loop around.*/ 1.42 + if (find->onlyAllowed) 1.43 + { 1.44 + /* Find the appropriate policy flag. */ 1.45 + policy = (&(policies->begin_ciphers)) + find->index + 1; 1.46 + 1.47 + /* If this cipher isn't allowed by policy, continue. */ 1.48 + if (! (*policy)) 1.49 + { 1.50 + rv = -1; 1.51 + find->index++; 1.52 + } 1.53 + } 1.54 + } 1.55 + 1.56 + return rv; 1.57 +} 1.58 + 1.59 +char sec_IsCipherAllowed(long cipher, secCPStruct *policies, 1.60 + long *ciphers) 1.61 +{ 1.62 + char result = SEC_CIPHER_NOT_ALLOWED; /* our default answer */ 1.63 + long numCiphers = policies->num_ciphers; 1.64 + char *policy; 1.65 + int i; 1.66 + 1.67 + /* Convert the cipher number into a policy flag location. */ 1.68 + for (i=0, policy=(&(policies->begin_ciphers) + 1); 1.69 + i<numCiphers; 1.70 + i++, policy++) 1.71 + { 1.72 + if (cipher == ciphers[i]) 1.73 + break; 1.74 + } 1.75 + 1.76 + if (i < numCiphers) 1.77 + { 1.78 + /* Found the cipher, get the policy value. */ 1.79 + result = *policy; 1.80 + } 1.81 + 1.82 + return result; 1.83 +} 1.84 + 1.85 +void sec_CipherFindEnd(SECCipherFind *find) 1.86 +{ 1.87 + PR_FREEIF(find); 1.88 +}