Back to index

lightning-sunbird  0.9+nobinonly
asn1.h
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 #ifndef ASN1_H
00038 #define ASN1_H
00039 
00040 #ifdef DEBUG
00041 static const char ASN1_CVS_ID[] = "@(#) $RCSfile: asn1.h,v $ $Revision: 1.3 $ $Date: 2005/01/20 02:25:44 $";
00042 #endif /* DEBUG */
00043 
00044 /*
00045  * asn1.h
00046  *
00047  * This file contains the ASN.1 encoder/decoder routines available
00048  * internally within NSS.  It's not clear right now if this file
00049  * will be folded into base.h or something, I just needed to get this
00050  * going.  At the moment, most of these routines wrap the old SEC_ASN1
00051  * calls.
00052  */
00053 
00054 #ifndef ASN1T_H
00055 #include "asn1t.h"
00056 #endif /* ASN1T_H */
00057 
00058 #ifndef BASE_H
00059 #include "base.h"
00060 #endif /* BASE_H */
00061 
00062 PR_BEGIN_EXTERN_C
00063 
00064 /*
00065  * nssASN1Decoder
00066  *
00067  * ... description here ...
00068  *
00069  *  nssASN1Decoder_Create (Factory/Constructor)
00070  *  nssASN1Decoder_Update
00071  *  nssASN1Decoder_Finish (Destructor)
00072  *  nssASN1Decoder_SetFilter
00073  *  nssASN1Decoder_GetFilter
00074  *  nssASN1Decoder_SetNotify
00075  *  nssASN1Decoder_GetNotify
00076  *
00077  * Debug builds only:
00078  *
00079  *  nssASN1Decoder_verify
00080  *
00081  * Related functions that aren't type methods:
00082  *
00083  *  nssASN1_Decode
00084  *  nssASN1_DecodeBER
00085  */
00086 
00087 /*
00088  * nssASN1Decoder_Create
00089  *
00090  * This routine creates an ASN.1 Decoder, which will use the specified
00091  * template to decode a datastream into the specified destination
00092  * structure.  If the optional arena argument is non-NULL, blah blah 
00093  * blah.  XXX fgmr Should we include an nssASN1EncodingType argument, 
00094  * as a hint?  Or is each encoding distinctive?  This routine may 
00095  * return NULL upon error, in which case an error will have been 
00096  * placed upon the error stack.
00097  *
00098  * The error may be one of the following values:
00099  *  NSS_ERROR_NO_MEMORY
00100  *  NSS_ERROR_INVALID_ARENA
00101  *  NSS_ERROR_INVALID_POINTER
00102  *  ...
00103  *
00104  * Return value:
00105  *  NULL upon error
00106  *  A pointer to an ASN.1 Decoder upon success.
00107  */
00108 
00109 NSS_EXTERN nssASN1Decoder *
00110 nssASN1Decoder_Create
00111 (
00112   NSSArena *arenaOpt,
00113   void *destination,
00114   const nssASN1Template template[]
00115 );
00116 
00117 extern const NSSError NSS_ERROR_NO_MEMORY;
00118 extern const NSSError NSS_ERROR_INVALID_ARENA;
00119 extern const NSSError NSS_ERROR_INVALID_POINTER;
00120 
00121 /*
00122  * nssASN1Decoder_Update
00123  *
00124  * This routine feeds data to the decoder.  In the event of an error, 
00125  * it will place an error on the error stack and return PR_FAILURE.
00126  *
00127  * The error may be one of the following values:
00128  *  NSS_ERROR_NO_MEMORY
00129  *  NSS_ERROR_INVALID_POINTER
00130  *  NSS_ERROR_INVALID_ASN1DECODER
00131  *  NSS_ERROR_INVALID_BER
00132  *  ...
00133  *
00134  * Return value:
00135  *  PR_FAILURE upon error
00136  *  PR_SUCCESS upon success.
00137  */
00138 
00139 NSS_EXTERN PRStatus
00140 nssASN1Decoder_Update
00141 (
00142   nssASN1Decoder *decoder,
00143   const void *data,
00144   PRUint32 amount
00145 );
00146 
00147 extern const NSSError NSS_ERROR_NO_MEMORY;
00148 extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
00149 extern const NSSError NSS_ERROR_INVALID_BER;
00150 
00151 /*
00152  * nssASN1Decoder_Finish
00153  *
00154  * This routine finishes the decoding and destroys the decoder.
00155  * In the event of an error, it will place an error on the error
00156  * stack and return PR_FAILURE.
00157  *
00158  * The error may be one of the following values:
00159  *  NSS_ERROR_INVALID_ASN1DECODER
00160  *
00161  * Return value:
00162  *  PR_FAILURE upon error
00163  *  PR_SUCCESS upon success
00164  */
00165 
00166 NSS_EXTERN PRStatus
00167 nssASN1Decoder_Finish
00168 (
00169   nssASN1Decoder *decoder
00170 );
00171 
00172 extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
00173 
00174 /*
00175  * nssASN1Decoder_SetFilter
00176  *
00177  * This routine registers a callback filter routine with the decoder,
00178  * which will be called blah blah blah.  The specified argument will
00179  * be passed as-is to the filter routine.  The routine pointer may
00180  * be NULL, in which case no filter callback will be called.  If the
00181  * noStore boolean is PR_TRUE, then decoded fields will not be stored
00182  * in the destination structure specified when the decoder was 
00183  * created.  This routine returns a PRStatus value; in the event of
00184  * an error, it will place an error on the error stack and return
00185  * PR_FAILURE.
00186  *
00187  * The error may be one of the following values:
00188  *  NSS_ERROR_INVALID_ASN1DECODER
00189  *
00190  * Return value:
00191  *  PR_FAILURE upon error
00192  *  PR_SUCCESS upon success
00193  */
00194 
00195 NSS_EXTERN PRStatus
00196 nssASN1Decoder_SetFilter
00197 (
00198   nssASN1Decoder *decoder,
00199   nssASN1DecoderFilterFunction *callback,
00200   void *argument,
00201   PRBool noStore
00202 );
00203 
00204 extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
00205 
00206 /*
00207  * nssASN1Decoder_GetFilter
00208  *
00209  * If the optional pCallbackOpt argument to this routine is non-null,
00210  * then the pointer to any callback function established for this
00211  * decoder with nssASN1Decoder_SetFilter will be stored at the 
00212  * location indicated by it.  If the optional pArgumentOpt
00213  * pointer is non-null, the filter's closure argument will be stored
00214  * there.  If the optional pNoStoreOpt pointer is non-null, the
00215  * noStore value specified when setting the filter will be stored
00216  * there.  This routine returns a PRStatus value; in the event of
00217  * an error it will place an error on the error stack and return
00218  * PR_FAILURE.
00219  *
00220  * The error may be one of the following values:
00221  *  NSS_ERROR_INVALID_ASN1DECODER
00222  *
00223  * Return value:
00224  *  PR_FAILURE upon error
00225  *  PR_SUCCESS upon success
00226  */
00227 
00228 NSS_EXTERN PRStatus
00229 nssASN1Decoder_GetFilter
00230 (
00231   nssASN1Decoder *decoder,
00232   nssASN1DecoderFilterFunction **pCallbackOpt,
00233   void **pArgumentOpt,
00234   PRBool *pNoStoreOpt
00235 );
00236 
00237 extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
00238 
00239 /*
00240  * nssASN1Decoder_SetNotify
00241  *
00242  * This routine registers a callback notify routine with the decoder,
00243  * which will be called whenever.. The specified argument will be
00244  * passed as-is to the notify routine.  The routine pointer may be
00245  * NULL, in which case no notify routine will be called.  This routine
00246  * returns a PRStatus value; in the event of an error it will place
00247  * an error on the error stack and return PR_FAILURE.
00248  *
00249  * The error may be one of the following values:
00250  *  NSS_ERROR_INVALID_ASN1DECODER
00251  *
00252  * Return value:
00253  *  PR_FAILURE upon error
00254  *  PR_SUCCESS upon success
00255  */
00256 
00257 NSS_EXTERN PRStatus
00258 nssASN1Decoder_SetNotify
00259 (
00260   nssASN1Decoder *decoder,
00261   nssASN1NotifyFunction *callback,
00262   void *argument
00263 );
00264 
00265 extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
00266 
00267 /*
00268  * nssASN1Decoder_GetNotify
00269  *
00270  * If the optional pCallbackOpt argument to this routine is non-null,
00271  * then the pointer to any callback function established for this
00272  * decoder with nssASN1Decoder_SetNotify will be stored at the 
00273  * location indicated by it.  If the optional pArgumentOpt pointer is
00274  * non-null, the filter's closure argument will be stored there.
00275  * This routine returns a PRStatus value; in the event of an error it
00276  * will place an error on the error stack and return PR_FAILURE.
00277  *
00278  * The error may be one of the following values:
00279  *  NSS_ERROR_INVALID_ASN1DECODER
00280  *
00281  * Return value:
00282  *  PR_FAILURE upon error
00283  *  PR_SUCCESS upon success
00284  */
00285 
00286 NSS_EXTERN PRStatus
00287 nssASN1Decoder_GetNotify
00288 (
00289   nssASN1Decoder *decoder,
00290   nssASN1NotifyFunction **pCallbackOpt,
00291   void **pArgumentOpt
00292 );
00293 
00294 extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
00295 
00296 /*
00297  * nssASN1Decoder_verify
00298  *
00299  * This routine is only available in debug builds.
00300  *
00301  * If the specified pointer is a valid pointer to an nssASN1Decoder
00302  * object, this routine will return PR_SUCCESS.  Otherwise, it will 
00303  * put an error on the error stack and return PR_FAILURE.
00304  *
00305  * The error may be one of the following values:
00306  *  NSS_ERROR_INVALID_ASN1DECODER
00307  *
00308  * Return value:
00309  *  PR_FAILURE upon error
00310  *  PR_SUCCESS upon success
00311  */
00312 
00313 #ifdef DEBUG
00314 NSS_EXTERN PRStatus
00315 nssASN1Decoder_verify
00316 (
00317   nssASN1Decoder *decoder
00318 );
00319 
00320 extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
00321 #endif /* DEBUG */
00322 
00323 /*
00324  * nssASN1_Decode
00325  *
00326  * This routine will decode the specified data into the specified
00327  * destination structure, as specified by the specified template.
00328  * This routine returns a PRStatus value; in the event of an error
00329  * it will place an error on the error stack and return PR_FAILURE.
00330  *
00331  * The error may be one of the following values:
00332  *  NSS_ERROR_NO_MEMORY
00333  *  NSS_ERROR_INVALID_ARENA
00334  *  NSS_ERROR_INVALID_POINTER
00335  *  NSS_ERROR_INVALID_BER
00336  *
00337  * Return value:
00338  *  PR_FAILURE upon error
00339  *  PR_SUCCESS upon success
00340  */
00341 
00342 NSS_EXTERN PRStatus
00343 nssASN1_Decode
00344 (
00345   NSSArena *arenaOpt,
00346   void *destination,
00347   const nssASN1Template template[],
00348   const void *berData,
00349   PRUint32 amount
00350 );
00351 
00352 extern const NSSError NSS_ERROR_NO_MEMORY;
00353 extern const NSSError NSS_ERROR_INVALID_ARENA;
00354 extern const NSSError NSS_ERROR_INVALID_POINTER;
00355 extern const NSSError NSS_ERROR_INVALID_BER;
00356 
00357 /*
00358  * nssASN1_DecodeBER
00359  *
00360  * This routine will decode the data in the specified NSSBER
00361  * into the destination structure, as specified by the template.
00362  * This routine returns a PRStatus value; in the event of an error
00363  * it will place an error on the error stack and return PR_FAILURE.
00364  *
00365  * The error may be one of the following values:
00366  *  NSS_ERROR_NO_MEMORY
00367  *  NSS_ERROR_INVALID_ARENA
00368  *  NSS_ERROR_INVALID_POINTER
00369  *  NSS_ERROR_INVALID_NSSBER
00370  *  NSS_ERROR_INVALID_BER
00371  *
00372  * Return value:
00373  *  PR_FAILURE upon error
00374  *  PR_SUCCESS upon success
00375  */
00376 
00377 NSS_EXTERN PRStatus
00378 nssASN1_DecodeBER
00379 (
00380   NSSArena *arenaOpt,
00381   void *destination,
00382   const nssASN1Template template[],
00383   const NSSBER *data
00384 );
00385 
00386 extern const NSSError NSS_ERROR_NO_MEMORY;
00387 extern const NSSError NSS_ERROR_INVALID_ARENA;
00388 extern const NSSError NSS_ERROR_INVALID_POINTER;
00389 extern const NSSError NSS_ERROR_INVALID_BER;
00390 
00391 /*
00392  * nssASN1Encoder
00393  *
00394  * ... description here ...
00395  *
00396  *  nssASN1Encoder_Create (Factory/Constructor)
00397  *  nssASN1Encoder_Update
00398  *  nssASN1Encoder_Finish (Destructor)
00399  *  nssASN1Encoder_SetNotify
00400  *  nssASN1Encoder_GetNotify
00401  *  nssASN1Encoder_SetStreaming
00402  *  nssASN1Encoder_GetStreaming
00403  *  nssASN1Encoder_SetTakeFromBuffer
00404  *  nssASN1Encoder_GetTakeFromBuffer
00405  *
00406  * Debug builds only:
00407  *
00408  *  nssASN1Encoder_verify
00409  *
00410  * Related functions that aren't type methods:
00411  *
00412  *  nssASN1_Encode
00413  *  nssASN1_EncodeItem
00414  */
00415 
00416 /*
00417  * nssASN1Encoder_Create
00418  *
00419  * This routine creates an ASN.1 Encoder, blah blah blah.  This 
00420  * may return NULL upon error, in which case an error will have been
00421  * placed on the error stack.
00422  *
00423  * The error may be one of the following values:
00424  *  NSS_ERROR_NO_MEMORY
00425  *  NSS_ERROR_INVALID_ARENA
00426  *  NSS_ERROR_INVALID_POINTER
00427  *  NSS_ERROR_ENCODING_NOT_SUPPORTED
00428  *  ...
00429  *
00430  * Return value:
00431  *  NULL upon error
00432  *  A pointer to an ASN.1 Encoder upon success
00433  */
00434 
00435 NSS_EXTERN nssASN1Encoder *
00436 nssASN1Encoder_Create
00437 (
00438   const void *source,
00439   const nssASN1Template template[],
00440   NSSASN1EncodingType encoding,
00441   nssASN1EncoderWriteFunction *sink,
00442   void *argument
00443 );
00444 
00445 extern const NSSError NSS_ERROR_NO_MEMORY;
00446 extern const NSSError NSS_ERROR_INVALID_ARENA;
00447 extern const NSSError NSS_ERROR_INVALID_POINTER;
00448 extern const NSSError NSS_ERROR_ENCODING_NOT_SUPPORTED;
00449 
00450 /*
00451  * nssASN1Encoder_Update
00452  *
00453  * The error may be one of the following values:
00454  *  NSS_ERROR_INVALID_ASN1ENCODER
00455  *  NSS_ERROR_INVALID_POINTER
00456  *
00457  * Return value:
00458  *  PR_FAILURE upon error
00459  *  PR_SUCCESS upon success
00460  */
00461 
00462 NSS_EXTERN PRStatus
00463 nssASN1Encoder_Update
00464 (
00465   nssASN1Encoder *encoder,
00466   const void *data,
00467   PRUint32 length
00468 );
00469 
00470 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00471 extern const NSSError NSS_ERROR_INVALID_POINTER;
00472 
00473 /*
00474  * nssASN1Encoder_Finish
00475  *
00476  * Destructor.
00477  *
00478  * The error may be one of the following values:
00479  *  NSS_ERROR_INVALID_ASN1ENCODER
00480  *
00481  * Return value:
00482  *  PR_FAILURE upon error
00483  *  PR_SUCCESS upon success
00484  */
00485 
00486 NSS_EXTERN PRStatus
00487 nssASN1Encoder_Finish
00488 (
00489   nssASN1Encoder *encoder
00490 );
00491 
00492 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00493 
00494 /*
00495  * nssASN1Encoder_SetNotify
00496  *
00497  * This routine registers a callback notify routine with the encoder,
00498  * which will be called whenever.. The specified argument will be
00499  * passed as-is to the notify routine.  The routine pointer may be
00500  * NULL, in which case no notify routine will be called.  This routine
00501  * returns a PRStatus value; in the event of an error it will place
00502  * an error on the error stack and return PR_FAILURE.
00503  *
00504  * The error may be one of the following values:
00505  *  NSS_ERROR_INVALID_ASN1DECODER
00506  *
00507  * Return value:
00508  *  PR_FAILURE upon error
00509  *  PR_SUCCESS upon success
00510  */
00511 
00512 NSS_EXTERN PRStatus
00513 nssASN1Encoder_SetNotify
00514 (
00515   nssASN1Encoder *encoder,
00516   nssASN1NotifyFunction *callback,
00517   void *argument
00518 );
00519 
00520 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00521 
00522 /*
00523  * nssASN1Encoder_GetNotify
00524  *
00525  * If the optional pCallbackOpt argument to this routine is non-null,
00526  * then the pointer to any callback function established for this
00527  * decoder with nssASN1Encoder_SetNotify will be stored at the 
00528  * location indicated by it.  If the optional pArgumentOpt pointer is
00529  * non-null, the filter's closure argument will be stored there.
00530  * This routine returns a PRStatus value; in the event of an error it
00531  * will place an error on the error stack and return PR_FAILURE.
00532  *
00533  * The error may be one of the following values:
00534  *  NSS_ERROR_INVALID_ASN1ENCODER
00535  *
00536  * Return value:
00537  *  PR_FAILURE upon error
00538  *  PR_SUCCESS upon success
00539  */
00540 
00541 NSS_EXTERN PRStatus
00542 nssASN1Encoder_GetNotify
00543 (
00544   nssASN1Encoder *encoder,
00545   nssASN1NotifyFunction **pCallbackOpt,
00546   void **pArgumentOpt
00547 );
00548 
00549 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00550 
00551 /*
00552  * nssASN1Encoder_SetStreaming
00553  *
00554  * 
00555  * The error may be one of the following values:
00556  *  NSS_ERROR_INVALID_ASN1ENCODER
00557  *
00558  * Return value:
00559  *  PR_FAILURE upon error
00560  *  PR_SUCCESS upon success
00561  */
00562 
00563 NSS_EXTERN PRStatus
00564 nssASN1Encoder_SetStreaming
00565 (
00566   nssASN1Encoder *encoder,
00567   PRBool streaming
00568 );
00569 
00570 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00571 
00572 /*
00573  * nssASN1Encoder_GetStreaming
00574  *
00575  *
00576  * The error may be one of the following values:
00577  *  NSS_ERROR_INVALID_ASN1ENCODER
00578  *  NSS_ERROR_INVALID_POINTER
00579  *
00580  * Return value:
00581  *  PR_FAILURE upon error
00582  *  PR_SUCCESS upon success
00583  */
00584 
00585 NSS_EXTERN PRStatus
00586 nssASN1Encoder_GetStreaming
00587 (
00588   nssASN1Encoder *encoder,
00589   PRBool *pStreaming
00590 );
00591 
00592 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00593 extern const NSSError NSS_ERROR_INVALID_POINTER;
00594 
00595 /*
00596  * nssASN1Encoder_SetTakeFromBuffer
00597  *
00598  *
00599  * The error may be one of the following values:
00600  *  NSS_ERROR_INVALID_ASN1ENCODER
00601  *
00602  * Return value:
00603  *  PR_FAILURE upon error
00604  *  PR_SUCCESS upon success
00605  */
00606 
00607 NSS_EXTERN PRStatus
00608 nssASN1Encoder_SetTakeFromBuffer
00609 (
00610   nssASN1Encoder *encoder,
00611   PRBool takeFromBuffer
00612 );
00613 
00614 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00615 
00616 /*
00617  * nssASN1Encoder_GetTakeFromBuffer
00618  *
00619  *
00620  * The error may be one of the following values:
00621  *  NSS_ERROR_INVALID_ASN1ENCODER
00622  *  NSS_ERROR_INVALID_POINTER
00623  *
00624  * Return value:
00625  *  PR_FAILURE upon error
00626  *  PR_SUCCESS upon success
00627  */
00628 
00629 NSS_EXTERN PRStatus
00630 nssASN1Encoder_GetTakeFromBuffer
00631 (
00632   nssASN1Encoder *encoder,
00633   PRBool *pTakeFromBuffer
00634 );
00635 
00636 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00637 extern const NSSError NSS_ERROR_INVALID_POINTER;
00638 
00639 /*
00640  * nssASN1Encoder_verify
00641  *
00642  * This routine is only available in debug builds.
00643  *
00644  * If the specified pointer is a valid pointer to an nssASN1Encoder
00645  * object, this routine will return PR_SUCCESS.  Otherwise, it will 
00646  * put an error on the error stack and return PR_FAILURE.
00647  *
00648  * The error may be one of the following values:
00649  *  NSS_ERROR_INVALID_ASN1ENCODER
00650  *
00651  * Return value:
00652  *  PR_FAILURE upon error
00653  *  PR_SUCCESS upon success
00654  */
00655 
00656 #ifdef DEBUG
00657 NSS_EXTERN PRStatus
00658 nssASN1Encoder_verify
00659 (
00660   nssASN1Encoder *encoder
00661 );
00662 
00663 extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
00664 #endif /* DEBUG */
00665 
00666 /*
00667  * nssASN1_Encode
00668  *
00669  * 
00670  * The error may be one of the following values:
00671  *  NSS_ERROR_NO_MEMORY
00672  *  NSS_ERROR_INVALID_ARENA
00673  *  NSS_ERROR_INVALID_POINTER
00674  *  NSS_ERROR_ENCODING_NOT_SUPPORTED
00675  *  ...
00676  *
00677  * Return value:
00678  *  PR_FAILURE upon error
00679  *  PR_SUCCESS upon success
00680  */
00681 
00682 NSS_EXTERN PRStatus
00683 nssASN1_Encode
00684 (
00685   const void *source,
00686   const nssASN1Template template[],
00687   NSSASN1EncodingType encoding,
00688   nssASN1EncoderWriteFunction *sink,
00689   void *argument
00690 );
00691 
00692 extern const NSSError NSS_ERROR_NO_MEMORY;
00693 extern const NSSError NSS_ERROR_INVALID_ARENA;
00694 extern const NSSError NSS_ERROR_INVALID_POINTER;
00695 extern const NSSError NSS_ERROR_ENCODING_NOT_SUPPORTED;
00696 
00697 /*
00698  * nssASN1_EncodeItem
00699  *
00700  * There must be a better name.  If the optional arena argument is
00701  * non-null, it'll be used for the space.  If the optional rvOpt is
00702  * non-null, it'll be the return value-- if it is null, a new one
00703  * will be allocated.
00704  *
00705  * The error may be one of the following values:
00706  *  NSS_ERROR_NO_MEMORY
00707  *  NSS_ERROR_INVALID_ARENA
00708  *  NSS_ERROR_INVALID_POINTER
00709  *  NSS_ERROR_ENCODING_NOT_SUPPORTED
00710  *
00711  * Return value:
00712  *  NULL upon error
00713  *  A valid pointer to an NSSDER upon success
00714  */
00715 
00716 NSS_EXTERN NSSDER *
00717 nssASN1_EncodeItem
00718 (
00719   NSSArena *arenaOpt,
00720   NSSDER *rvOpt,
00721   const void *source,
00722   const nssASN1Template template[],
00723   NSSASN1EncodingType encoding
00724 );
00725 
00726 extern const NSSError NSS_ERROR_NO_MEMORY;
00727 extern const NSSError NSS_ERROR_INVALID_ARENA;
00728 extern const NSSError NSS_ERROR_INVALID_POINTER;
00729 extern const NSSError NSS_ERROR_ENCODING_NOT_SUPPORTED;
00730 
00731 /*
00732  * Other basic types' encoding and decoding helper functions:
00733  *
00734  *  nssASN1_CreatePRUint32FromBER
00735  *  nssASN1_GetDERFromPRUint32
00736  *  nssASN1_CreatePRInt32FromBER
00737  *  nssASN1_GetDERFromPRInt32
00738  * ..etc..
00739  */
00740 
00741 /*
00742  * nssASN1_CreatePRUint32FromBER
00743  *
00744  */
00745 
00746 NSS_EXTERN PRStatus
00747 nssASN1_CreatePRUint32FromBER
00748 (
00749   NSSBER *encoded,
00750   PRUint32 *pResult
00751 );
00752 
00753 /*
00754  * nssASN1_GetDERFromPRUint32
00755  *
00756  */
00757 
00758 NSS_EXTERN NSSDER *
00759 nssASN1_GetDERFromPRUint32
00760 (
00761   NSSArena *arenaOpt,
00762   NSSDER *rvOpt,
00763   PRUint32 value
00764 );
00765 
00766 /*
00767  * nssASN1_CreatePRInt32FromBER
00768  *
00769  */
00770 
00771 NSS_EXTERN PRStatus
00772 nssASN1_CreatePRInt32FromBER
00773 (
00774   NSSBER *encoded,
00775   PRInt32 *pResult
00776 );
00777 
00778 /*
00779  * nssASN1_GetDERFromPRInt32
00780  *
00781  */
00782 
00783 NSS_EXTERN NSSDER *
00784 nssASN1_GetDERFromPRInt32
00785 (
00786   NSSArena *arenaOpt,
00787   NSSDER *rvOpt,
00788   PRInt32 value
00789 );
00790 
00791 /*
00792  * Builtin templates
00793  */
00794 
00795 /*
00796  * Generic Templates
00797  * One for each of the simple types, plus a special one for ANY, plus:
00798  *     - a pointer to each one of those
00799  *     - a set of each one of those
00800  *
00801  * Note that these are alphabetical (case insensitive); please add new
00802  * ones in the appropriate place.
00803  */
00804 
00805 extern const nssASN1Template *nssASN1Template_Any;
00806 extern const nssASN1Template *nssASN1Template_BitString;
00807 extern const nssASN1Template *nssASN1Template_BMPString;
00808 extern const nssASN1Template *nssASN1Template_Boolean;
00809 extern const nssASN1Template *nssASN1Template_Enumerated;
00810 extern const nssASN1Template *nssASN1Template_GeneralizedTime;
00811 extern const nssASN1Template *nssASN1Template_IA5String;
00812 extern const nssASN1Template *nssASN1Template_Integer;
00813 extern const nssASN1Template *nssASN1Template_Null;
00814 extern const nssASN1Template *nssASN1Template_ObjectID;
00815 extern const nssASN1Template *nssASN1Template_OctetString;
00816 extern const nssASN1Template *nssASN1Template_PrintableString;
00817 extern const nssASN1Template *nssASN1Template_T61String;
00818 extern const nssASN1Template *nssASN1Template_UniversalString;
00819 extern const nssASN1Template *nssASN1Template_UTCTime;
00820 extern const nssASN1Template *nssASN1Template_UTF8String;
00821 extern const nssASN1Template *nssASN1Template_VisibleString;
00822 
00823 extern const nssASN1Template *nssASN1Template_PointerToAny;
00824 extern const nssASN1Template *nssASN1Template_PointerToBitString;
00825 extern const nssASN1Template *nssASN1Template_PointerToBMPString;
00826 extern const nssASN1Template *nssASN1Template_PointerToBoolean;
00827 extern const nssASN1Template *nssASN1Template_PointerToEnumerated;
00828 extern const nssASN1Template *nssASN1Template_PointerToGeneralizedTime;
00829 extern const nssASN1Template *nssASN1Template_PointerToIA5String;
00830 extern const nssASN1Template *nssASN1Template_PointerToInteger;
00831 extern const nssASN1Template *nssASN1Template_PointerToNull;
00832 extern const nssASN1Template *nssASN1Template_PointerToObjectID;
00833 extern const nssASN1Template *nssASN1Template_PointerToOctetString;
00834 extern const nssASN1Template *nssASN1Template_PointerToPrintableString;
00835 extern const nssASN1Template *nssASN1Template_PointerToT61String;
00836 extern const nssASN1Template *nssASN1Template_PointerToUniversalString;
00837 extern const nssASN1Template *nssASN1Template_PointerToUTCTime;
00838 extern const nssASN1Template *nssASN1Template_PointerToUTF8String;
00839 extern const nssASN1Template *nssASN1Template_PointerToVisibleString;
00840 
00841 extern const nssASN1Template *nssASN1Template_SetOfAny;
00842 extern const nssASN1Template *nssASN1Template_SetOfBitString;
00843 extern const nssASN1Template *nssASN1Template_SetOfBMPString;
00844 extern const nssASN1Template *nssASN1Template_SetOfBoolean;
00845 extern const nssASN1Template *nssASN1Template_SetOfEnumerated;
00846 extern const nssASN1Template *nssASN1Template_SetOfGeneralizedTime;
00847 extern const nssASN1Template *nssASN1Template_SetOfIA5String;
00848 extern const nssASN1Template *nssASN1Template_SetOfInteger;
00849 extern const nssASN1Template *nssASN1Template_SetOfNull;
00850 extern const nssASN1Template *nssASN1Template_SetOfObjectID;
00851 extern const nssASN1Template *nssASN1Template_SetOfOctetString;
00852 extern const nssASN1Template *nssASN1Template_SetOfPrintableString;
00853 extern const nssASN1Template *nssASN1Template_SetOfT61String;
00854 extern const nssASN1Template *nssASN1Template_SetOfUniversalString;
00855 extern const nssASN1Template *nssASN1Template_SetOfUTCTime;
00856 extern const nssASN1Template *nssASN1Template_SetOfUTF8String;
00857 extern const nssASN1Template *nssASN1Template_SetOfVisibleString;
00858 
00859 /*
00860  *
00861  */
00862 
00863 NSS_EXTERN NSSUTF8 *
00864 nssUTF8_CreateFromBER
00865 (
00866   NSSArena *arenaOpt,
00867   nssStringType type,
00868   NSSBER *berData
00869 );
00870 
00871 NSS_EXTERN NSSDER *
00872 nssUTF8_GetDEREncoding
00873 (
00874   NSSArena *arenaOpt,
00875   /* Should have an NSSDER *rvOpt */
00876   nssStringType type,
00877   const NSSUTF8 *string
00878 );
00879 
00880 PR_END_EXTERN_C
00881 
00882 #endif /* ASN1_H */