Thanks for the detailed info! Weidong Nelson B wrote: > Wei Shao wrote: > > > can someone explain how the ASN1 template works in general, > > http://www.google.com/search?hl=en&q=asn.1+template+site%3Amozilla.org > will show you the available documentation on NSS's ASN.1 templates. > See especially > http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn1.html > > The same template arrays are used by the encoder and decoders. The > template documentation is presently included in the decoder documents. > The encoders and decoders have essentially the same APIs, but work in > opposite directions (i.e. the encoded buffer is input to the decoder > and output from the encoder). > > There is generally a one-to-one correspondence between a template > array and a structure that contains the decoded (or not-yet-encoded) > contents. The template arrays describe the structure to the encoder > and decoder. > > > and in particular, if the template definition for the field is > > > > SEC_ASN1_OPTIONAL | SEC_ASN1_ANY > > These symbols correspond to the ASN.1 symbols OPTIONAL and ANY. > > An missing optional item is decoded to a NULL data ptr in the corresponding > SECItem. An optional item with a NULL data ptr in the SECItem will not > be encoded. > > An "ANY" item is not decoded or encoded, but is placed into (or taken from) > the corresponding SECItem's buffer in encoded form. > > Prior to calling the encoder to encode an ANY, the caller must have already > DER/BER encoded the buffer containing the ANY. This is usually accomplished > with a separate call to the encoder. > > > In this case, if I want to put a SEC_ASN1_OCTET_STRING data to the > > filed, will the encoding/decoding work? or do I need to change the > > template definition? > > Most of NSS's template arrays are used in multiple places in NSS. Therefore, > You should not change any of NSS's template arrays. If you need a different > template, you should make your own new one(s). > > > Also, how does encoding maps from a C object? e.g, if I have the data > > in the SECItem structure (which has type, len, data fields), what do I > > need to do if I want to encode that data into the above field in the > > SEC_ASN1Template? > > I suggest you look at this function for an example of a very simple use > of the encoder. > > http://lxr.mozilla.org/security/ident?i=CERT_EncodeSubjectKeyID > > > Finally, In secasn1e.c, SEC_ASN1EncodeItem uses SEC_ASN1Encode. But I > > have not found where that function (SEC_ASN1Encode() ) is defined. > > http://lxr.mozilla.org/security/ident?i=SEC_ASN1Encode > > > Thanks, > > Wei > > -- > Nelson B
_______________________________________________ dev-tech-crypto mailing list dev-tech-crypto@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-tech-crypto