PInsertRelativeDistinguishedName.c
上传用户:lyxiangda
上传日期:2007-01-12
资源大小:3042k
文件大小:4k
源码类别:

CA认证

开发平台:

WINDOWS

  1. /* 
  2.  * The contents of this file are subject to the Mozilla Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/MPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is the Netscape security libraries.
  13.  * 
  14.  * The Initial Developer of the Original Code is Netscape
  15.  * Communications Corporation.  Portions created by Netscape are 
  16.  * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
  17.  * Rights Reserved.
  18.  * 
  19.  * Contributor(s):
  20.  * 
  21.  * Alternatively, the contents of this file may be used under the
  22.  * terms of the GNU General Public License Version 2 or later (the
  23.  * "GPL"), in which case the provisions of the GPL are applicable 
  24.  * instead of those above.  If you wish to allow use of your 
  25.  * version of this file only under the terms of the GPL and not to
  26.  * allow others to use your version of this file under the MPL,
  27.  * indicate your decision by deleting the provisions above and
  28.  * replace them with the notice and other provisions required by
  29.  * the GPL.  If you do not delete the provisions above, a recipient
  30.  * may use your version of this file under either the MPL or the
  31.  * GPL.
  32.  */
  33. #ifdef DEBUG
  34. static const char CVS_ID[] = "@(#) $Source: /cvsroot/mozilla/security/nss/lib/pkix/src/RDNSequence/PInsertRelativeDistinguishedName.c,v $ $Revision: 1.1 $ $Date: 2000/03/31 19:14:15 $ $Name: NSS_3_1_1_RTM $";
  35. #endif /* DEBUG */
  36. #ifndef PKIX_H
  37. #include "pkix.h"
  38. #endif /* PKIX_H */
  39. /*
  40.  * nssPKIXRDNSequence_InsertRelativeDistinguishedName
  41.  *
  42.  * -- fgmr comments --
  43.  *
  44.  * The error may be one of the following values:
  45.  *  NSS_ERROR_INVALID_PKIX_RDN_SEQUENCE
  46.  *  NSS_ERROR_INVALID_PKIX_RDN
  47.  *  NSS_ERROR_NO_MEMORY
  48.  *
  49.  * Return value:
  50.  *  PR_SUCCESS upon success
  51.  *  PR_FAILURE upon failure
  52.  */
  53. NSS_IMPLEMENT PRStatus
  54. nssPKIXRDNSequence_InsertRelativeDistinguishedName
  55. (
  56.   NSSPKIXRDNSequence *rdnseq,
  57.   PRInt32 i,
  58.   NSSPKIXRelativeDistinguishedName *rdn
  59. )
  60. {
  61.   NSSPKIXRelativeDistinguishedName **na;
  62.   NSSPKIXRelativeDistinguishedName *dup;
  63.   PRInt32 c;
  64. #ifdef NSSDEBUG
  65.   if( PR_SUCCESS != nssPKIXRDNSequence_verifyPointer(rdnseq) ) {
  66.     return PR_FAILURE;
  67.   }
  68.   if( PR_SUCCESS != nssPKIXRelativeDistinguishedName_verifyPointer(rdn) ) {
  69.     return PR_FAILURE;
  70.   }
  71. #endif /* NSSDEBUG */
  72.   if( 0 == rdnseq->count ) {
  73.     nss_pkix_RDNSequence_Count(rdnseq);
  74.   }
  75. #ifdef PEDANTIC
  76.   if( 0 == rdnseq->count ) {
  77.     nss_SetError(NSS_ERROR_VALUE_OUT_OF_RANGE);
  78.     return (NSSPKIXRelativeDistinguishedName *)NULL;
  79.   }
  80. #endif /* PEDANTIC */
  81.   if( (i < 0) || (i >= rdnseq->count) ) {
  82.     nss_SetError(NSS_ERROR_VALUE_OUT_OF_RANGE);
  83.     return (NSSPKIXRelativeDistinguishedName *)NULL;
  84.   }
  85.   na = (NSSPKIXRelativeDistinguishedName **)
  86.     nss_ZRealloc(rdnseq->rdns, ((rdnseq->count+2) * 
  87.       sizeof(NSSPKIXRelativeDistinguishedName *)));
  88.   if( (NSSPKIXRelativeDistinguishedName **)NULL == na ) {
  89.     return (NSSPKIXRelativeDistinguishedName *)NULL;
  90.   }
  91.   rdnseq->rdns = na;
  92.   dup = nssPKIXRelativeDistinguishedName_Duplicate(rdn, rdnseq->arena);
  93.   if( (NSSPKIXRelativeDistinguishedName *)NULL == dup ) {
  94.     return (NSSPKIXRelativeDistinguishedName *)NULL;
  95.   }
  96.   for( c = rdnseq->count; c > i; c-- ) {
  97.     na[ c ] = na[ c-1 ];
  98.   }
  99.   na[ i ] = dup;
  100.   rdnseq->count++;
  101.   return nss_pkix_RDNSequence_Clear(rdnseq);
  102. }