Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / security / nss / lib / smime / cmsdigdata.c
blob41eefe3c4da7ae636e323b31fe0098b22aa0d479
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
38 * CMS digestedData methods.
40 * $Id: cmsdigdata.c,v 1.5 2004/04/25 15:03:16 gerv%gerv.net Exp $
43 #include "cmslocal.h"
45 #include "secitem.h"
46 #include "secasn1.h"
47 #include "secoid.h"
48 #include "secerr.h"
51 * NSS_CMSDigestedData_Create - create a digestedData object (presumably for encoding)
53 * version will be set by NSS_CMSDigestedData_Encode_BeforeStart
54 * digestAlg is passed as parameter
55 * contentInfo must be filled by the user
56 * digest will be calculated while encoding
58 NSSCMSDigestedData *
59 NSS_CMSDigestedData_Create(NSSCMSMessage *cmsg, SECAlgorithmID *digestalg)
61 void *mark;
62 NSSCMSDigestedData *digd;
63 PLArenaPool *poolp;
65 poolp = cmsg->poolp;
67 mark = PORT_ArenaMark(poolp);
69 digd = (NSSCMSDigestedData *)PORT_ArenaZAlloc(poolp, sizeof(NSSCMSDigestedData));
70 if (digd == NULL)
71 goto loser;
73 digd->cmsg = cmsg;
75 if (SECOID_CopyAlgorithmID (poolp, &(digd->digestAlg), digestalg) != SECSuccess)
76 goto loser;
78 PORT_ArenaUnmark(poolp, mark);
79 return digd;
81 loser:
82 PORT_ArenaRelease(poolp, mark);
83 return NULL;
87 * NSS_CMSDigestedData_Destroy - destroy a digestedData object
89 void
90 NSS_CMSDigestedData_Destroy(NSSCMSDigestedData *digd)
92 /* everything's in a pool, so don't worry about the storage */
93 NSS_CMSContentInfo_Destroy(&(digd->contentInfo));
94 return;
98 * NSS_CMSDigestedData_GetContentInfo - return pointer to digestedData object's contentInfo
100 NSSCMSContentInfo *
101 NSS_CMSDigestedData_GetContentInfo(NSSCMSDigestedData *digd)
103 return &(digd->contentInfo);
107 * NSS_CMSDigestedData_Encode_BeforeStart - do all the necessary things to a DigestedData
108 * before encoding begins.
110 * In particular:
111 * - set the right version number. The contentInfo's content type must be set up already.
113 SECStatus
114 NSS_CMSDigestedData_Encode_BeforeStart(NSSCMSDigestedData *digd)
116 unsigned long version;
117 SECItem *dummy;
119 version = NSS_CMS_DIGESTED_DATA_VERSION_DATA;
120 if (NSS_CMSContentInfo_GetContentTypeTag(&(digd->contentInfo)) != SEC_OID_PKCS7_DATA)
121 version = NSS_CMS_DIGESTED_DATA_VERSION_ENCAP;
123 dummy = SEC_ASN1EncodeInteger(digd->cmsg->poolp, &(digd->version), version);
124 return (dummy == NULL) ? SECFailure : SECSuccess;
128 * NSS_CMSDigestedData_Encode_BeforeData - do all the necessary things to a DigestedData
129 * before the encapsulated data is passed through the encoder.
131 * In detail:
132 * - set up the digests if necessary
134 SECStatus
135 NSS_CMSDigestedData_Encode_BeforeData(NSSCMSDigestedData *digd)
137 /* set up the digests */
138 if (digd->digestAlg.algorithm.len != 0 && digd->digest.len == 0) {
139 /* if digest is already there, do nothing */
140 digd->contentInfo.digcx = NSS_CMSDigestContext_StartSingle(&(digd->digestAlg));
141 if (digd->contentInfo.digcx == NULL)
142 return SECFailure;
144 return SECSuccess;
148 * NSS_CMSDigestedData_Encode_AfterData - do all the necessary things to a DigestedData
149 * after all the encapsulated data was passed through the encoder.
151 * In detail:
152 * - finish the digests
154 SECStatus
155 NSS_CMSDigestedData_Encode_AfterData(NSSCMSDigestedData *digd)
157 SECStatus rv = SECSuccess;
158 /* did we have digest calculation going on? */
159 if (digd->contentInfo.digcx) {
160 rv = NSS_CMSDigestContext_FinishSingle(digd->contentInfo.digcx,
161 digd->cmsg->poolp,
162 &(digd->digest));
163 /* error has been set by NSS_CMSDigestContext_FinishSingle */
164 digd->contentInfo.digcx = NULL;
167 return rv;
171 * NSS_CMSDigestedData_Decode_BeforeData - do all the necessary things to a DigestedData
172 * before the encapsulated data is passed through the encoder.
174 * In detail:
175 * - set up the digests if necessary
177 SECStatus
178 NSS_CMSDigestedData_Decode_BeforeData(NSSCMSDigestedData *digd)
180 /* is there a digest algorithm yet? */
181 if (digd->digestAlg.algorithm.len == 0)
182 return SECFailure;
184 digd->contentInfo.digcx = NSS_CMSDigestContext_StartSingle(&(digd->digestAlg));
185 if (digd->contentInfo.digcx == NULL)
186 return SECFailure;
188 return SECSuccess;
192 * NSS_CMSDigestedData_Decode_AfterData - do all the necessary things to a DigestedData
193 * after all the encapsulated data was passed through the encoder.
195 * In detail:
196 * - finish the digests
198 SECStatus
199 NSS_CMSDigestedData_Decode_AfterData(NSSCMSDigestedData *digd)
201 SECStatus rv = SECSuccess;
202 /* did we have digest calculation going on? */
203 if (digd->contentInfo.digcx) {
204 rv = NSS_CMSDigestContext_FinishSingle(digd->contentInfo.digcx,
205 digd->cmsg->poolp,
206 &(digd->cdigest));
207 /* error has been set by NSS_CMSDigestContext_FinishSingle */
208 digd->contentInfo.digcx = NULL;
211 return rv;
215 * NSS_CMSDigestedData_Decode_AfterEnd - finalize a digestedData.
217 * In detail:
218 * - check the digests for equality
220 SECStatus
221 NSS_CMSDigestedData_Decode_AfterEnd(NSSCMSDigestedData *digd)
223 /* did we have digest calculation going on? */
224 if (digd->cdigest.len != 0) {
225 /* XXX comparision btw digest & cdigest */
226 /* XXX set status */
227 /* TODO!!!! */
230 return SECSuccess;