1183234Ssimon/* crypto/cms/cms_att.c */
2296465Sdelphij/*
3296465Sdelphij * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
4183234Ssimon * project.
5183234Ssimon */
6183234Ssimon/* ====================================================================
7183234Ssimon * Copyright (c) 2008 The OpenSSL Project.  All rights reserved.
8183234Ssimon *
9183234Ssimon * Redistribution and use in source and binary forms, with or without
10183234Ssimon * modification, are permitted provided that the following conditions
11183234Ssimon * are met:
12183234Ssimon *
13183234Ssimon * 1. Redistributions of source code must retain the above copyright
14296465Sdelphij *    notice, this list of conditions and the following disclaimer.
15183234Ssimon *
16183234Ssimon * 2. Redistributions in binary form must reproduce the above copyright
17183234Ssimon *    notice, this list of conditions and the following disclaimer in
18183234Ssimon *    the documentation and/or other materials provided with the
19183234Ssimon *    distribution.
20183234Ssimon *
21183234Ssimon * 3. All advertising materials mentioning features or use of this
22183234Ssimon *    software must display the following acknowledgment:
23183234Ssimon *    "This product includes software developed by the OpenSSL Project
24183234Ssimon *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25183234Ssimon *
26183234Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27183234Ssimon *    endorse or promote products derived from this software without
28183234Ssimon *    prior written permission. For written permission, please contact
29183234Ssimon *    licensing@OpenSSL.org.
30183234Ssimon *
31183234Ssimon * 5. Products derived from this software may not be called "OpenSSL"
32183234Ssimon *    nor may "OpenSSL" appear in their names without prior written
33183234Ssimon *    permission of the OpenSSL Project.
34183234Ssimon *
35183234Ssimon * 6. Redistributions of any form whatsoever must retain the following
36183234Ssimon *    acknowledgment:
37183234Ssimon *    "This product includes software developed by the OpenSSL Project
38183234Ssimon *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39183234Ssimon *
40183234Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41183234Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42183234Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43183234Ssimon * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44183234Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45183234Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46183234Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47183234Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48183234Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49183234Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50183234Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51183234Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE.
52183234Ssimon * ====================================================================
53183234Ssimon */
54183234Ssimon
55183234Ssimon#include <openssl/asn1t.h>
56183234Ssimon#include <openssl/pem.h>
57183234Ssimon#include <openssl/x509v3.h>
58183234Ssimon#include <openssl/err.h>
59183234Ssimon#include "cms.h"
60183234Ssimon#include "cms_lcl.h"
61183234Ssimon
62183234Ssimon/* CMS SignedData Attribute utilities */
63183234Ssimon
64183234Ssimonint CMS_signed_get_attr_count(const CMS_SignerInfo *si)
65183234Ssimon{
66296465Sdelphij    return X509at_get_attr_count(si->signedAttrs);
67183234Ssimon}
68183234Ssimon
69296465Sdelphijint CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, int lastpos)
70183234Ssimon{
71296465Sdelphij    return X509at_get_attr_by_NID(si->signedAttrs, nid, lastpos);
72183234Ssimon}
73183234Ssimon
74183234Ssimonint CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, ASN1_OBJECT *obj,
75296465Sdelphij                               int lastpos)
76183234Ssimon{
77296465Sdelphij    return X509at_get_attr_by_OBJ(si->signedAttrs, obj, lastpos);
78183234Ssimon}
79183234Ssimon
80183234SsimonX509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc)
81183234Ssimon{
82296465Sdelphij    return X509at_get_attr(si->signedAttrs, loc);
83183234Ssimon}
84183234Ssimon
85183234SsimonX509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc)
86183234Ssimon{
87296465Sdelphij    return X509at_delete_attr(si->signedAttrs, loc);
88183234Ssimon}
89183234Ssimon
90183234Ssimonint CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
91183234Ssimon{
92296465Sdelphij    if (X509at_add1_attr(&si->signedAttrs, attr))
93296465Sdelphij        return 1;
94296465Sdelphij    return 0;
95183234Ssimon}
96183234Ssimon
97183234Ssimonint CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
98296465Sdelphij                                const ASN1_OBJECT *obj, int type,
99296465Sdelphij                                const void *bytes, int len)
100183234Ssimon{
101296465Sdelphij    if (X509at_add1_attr_by_OBJ(&si->signedAttrs, obj, type, bytes, len))
102296465Sdelphij        return 1;
103296465Sdelphij    return 0;
104183234Ssimon}
105183234Ssimon
106183234Ssimonint CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
107296465Sdelphij                                int nid, int type, const void *bytes, int len)
108183234Ssimon{
109296465Sdelphij    if (X509at_add1_attr_by_NID(&si->signedAttrs, nid, type, bytes, len))
110296465Sdelphij        return 1;
111296465Sdelphij    return 0;
112183234Ssimon}
113183234Ssimon
114183234Ssimonint CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
115296465Sdelphij                                const char *attrname, int type,
116296465Sdelphij                                const void *bytes, int len)
117183234Ssimon{
118296465Sdelphij    if (X509at_add1_attr_by_txt(&si->signedAttrs, attrname, type, bytes, len))
119296465Sdelphij        return 1;
120296465Sdelphij    return 0;
121183234Ssimon}
122183234Ssimon
123183234Ssimonvoid *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
124296465Sdelphij                                  int lastpos, int type)
125183234Ssimon{
126296465Sdelphij    return X509at_get0_data_by_OBJ(si->signedAttrs, oid, lastpos, type);
127183234Ssimon}
128183234Ssimon
129183234Ssimonint CMS_unsigned_get_attr_count(const CMS_SignerInfo *si)
130183234Ssimon{
131296465Sdelphij    return X509at_get_attr_count(si->unsignedAttrs);
132183234Ssimon}
133183234Ssimon
134183234Ssimonint CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
135296465Sdelphij                                 int lastpos)
136183234Ssimon{
137296465Sdelphij    return X509at_get_attr_by_NID(si->unsignedAttrs, nid, lastpos);
138183234Ssimon}
139183234Ssimon
140183234Ssimonint CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, ASN1_OBJECT *obj,
141296465Sdelphij                                 int lastpos)
142183234Ssimon{
143296465Sdelphij    return X509at_get_attr_by_OBJ(si->unsignedAttrs, obj, lastpos);
144183234Ssimon}
145183234Ssimon
146183234SsimonX509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc)
147183234Ssimon{
148296465Sdelphij    return X509at_get_attr(si->unsignedAttrs, loc);
149183234Ssimon}
150183234Ssimon
151183234SsimonX509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc)
152183234Ssimon{
153296465Sdelphij    return X509at_delete_attr(si->unsignedAttrs, loc);
154183234Ssimon}
155183234Ssimon
156183234Ssimonint CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
157183234Ssimon{
158296465Sdelphij    if (X509at_add1_attr(&si->unsignedAttrs, attr))
159296465Sdelphij        return 1;
160296465Sdelphij    return 0;
161183234Ssimon}
162183234Ssimon
163183234Ssimonint CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
164296465Sdelphij                                  const ASN1_OBJECT *obj, int type,
165296465Sdelphij                                  const void *bytes, int len)
166183234Ssimon{
167296465Sdelphij    if (X509at_add1_attr_by_OBJ(&si->unsignedAttrs, obj, type, bytes, len))
168296465Sdelphij        return 1;
169296465Sdelphij    return 0;
170183234Ssimon}
171183234Ssimon
172183234Ssimonint CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
173296465Sdelphij                                  int nid, int type,
174296465Sdelphij                                  const void *bytes, int len)
175183234Ssimon{
176296465Sdelphij    if (X509at_add1_attr_by_NID(&si->unsignedAttrs, nid, type, bytes, len))
177296465Sdelphij        return 1;
178296465Sdelphij    return 0;
179183234Ssimon}
180183234Ssimon
181183234Ssimonint CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
182296465Sdelphij                                  const char *attrname, int type,
183296465Sdelphij                                  const void *bytes, int len)
184183234Ssimon{
185296465Sdelphij    if (X509at_add1_attr_by_txt(&si->unsignedAttrs, attrname,
186296465Sdelphij                                type, bytes, len))
187296465Sdelphij        return 1;
188296465Sdelphij    return 0;
189183234Ssimon}
190183234Ssimon
191183234Ssimonvoid *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
192296465Sdelphij                                    int lastpos, int type)
193183234Ssimon{
194296465Sdelphij    return X509at_get0_data_by_OBJ(si->unsignedAttrs, oid, lastpos, type);
195183234Ssimon}
196183234Ssimon
197183234Ssimon/* Specific attribute cases */
198