Back to index

lightning-sunbird  0.9+nobinonly
secplcy.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "secplcy.h"
00038 #include "prmem.h"
00039 
00040 SECCipherFind *sec_CipherFindInit(PRBool onlyAllowed,
00041                               secCPStruct *policy,
00042                               long *ciphers)
00043 {
00044   SECCipherFind *find = PR_NEWZAP(SECCipherFind);
00045   if (find)
00046     {
00047       find->policy = policy;
00048       find->ciphers = ciphers;
00049       find->onlyAllowed = onlyAllowed;
00050       find->index = -1;
00051     }
00052   return find;
00053 }
00054 
00055 long sec_CipherFindNext(SECCipherFind *find)
00056 {
00057   char *policy;
00058   long rv = -1;
00059   secCPStruct *policies = (secCPStruct *) find->policy;
00060   long *ciphers = (long *) find->ciphers;
00061   long numCiphers = policies->num_ciphers;
00062 
00063   find->index++;
00064   while((find->index < numCiphers) && (rv == -1))
00065     {
00066       /* Translate index to cipher. */
00067       rv = ciphers[find->index];
00068 
00069       /* If we're only looking for allowed ciphers, and if this
00070         cipher isn't allowed, loop around.*/
00071       if (find->onlyAllowed)
00072        {
00073          /* Find the appropriate policy flag. */
00074          policy = (&(policies->begin_ciphers)) + find->index + 1;
00075 
00076          /* If this cipher isn't allowed by policy, continue. */
00077          if (! (*policy))
00078            {
00079              rv = -1;
00080              find->index++;
00081            }
00082        }
00083     }
00084 
00085   return rv;
00086 }
00087 
00088 char sec_IsCipherAllowed(long cipher, secCPStruct *policies,
00089                       long *ciphers)
00090 {
00091   char result = SEC_CIPHER_NOT_ALLOWED; /* our default answer */
00092   long numCiphers = policies->num_ciphers;
00093   char *policy;
00094   int i;
00095   
00096   /* Convert the cipher number into a policy flag location. */
00097   for (i=0, policy=(&(policies->begin_ciphers) + 1);
00098        i<numCiphers;
00099        i++, policy++)
00100     {
00101       if (cipher == ciphers[i])
00102        break;
00103     }
00104 
00105   if (i < numCiphers)
00106     {
00107       /* Found the cipher, get the policy value. */
00108       result = *policy;
00109     }
00110 
00111   return result;
00112 }
00113 
00114 void sec_CipherFindEnd(SECCipherFind *find)
00115 {
00116   PR_FREEIF(find);
00117 }