664e64971b0ac7561873ba747e82415255d3ec14
[openssl.git] / crypto / cms / cms_att.c
1 /*
2  * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <openssl/asn1t.h>
11 #include <openssl/pem.h>
12 #include <openssl/x509v3.h>
13 #include <openssl/err.h>
14 #include <openssl/cms.h>
15 #include "cms_lcl.h"
16
17 /* CMS SignedData Attribute utilities */
18
19 int CMS_signed_get_attr_count(const CMS_SignerInfo *si)
20 {
21     return X509at_get_attr_count(si->signedAttrs);
22 }
23
24 int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, int lastpos)
25 {
26     return X509at_get_attr_by_NID(si->signedAttrs, nid, lastpos);
27 }
28
29 int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
30                                int lastpos)
31 {
32     return X509at_get_attr_by_OBJ(si->signedAttrs, obj, lastpos);
33 }
34
35 X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc)
36 {
37     return X509at_get_attr(si->signedAttrs, loc);
38 }
39
40 X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc)
41 {
42     return X509at_delete_attr(si->signedAttrs, loc);
43 }
44
45 int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
46 {
47     if (X509at_add1_attr(&si->signedAttrs, attr))
48         return 1;
49     return 0;
50 }
51
52 int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
53                                 const ASN1_OBJECT *obj, int type,
54                                 const void *bytes, int len)
55 {
56     if (X509at_add1_attr_by_OBJ(&si->signedAttrs, obj, type, bytes, len))
57         return 1;
58     return 0;
59 }
60
61 int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
62                                 int nid, int type, const void *bytes, int len)
63 {
64     if (X509at_add1_attr_by_NID(&si->signedAttrs, nid, type, bytes, len))
65         return 1;
66     return 0;
67 }
68
69 int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
70                                 const char *attrname, int type,
71                                 const void *bytes, int len)
72 {
73     if (X509at_add1_attr_by_txt(&si->signedAttrs, attrname, type, bytes, len))
74         return 1;
75     return 0;
76 }
77
78 void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *oid,
79                                   int lastpos, int type)
80 {
81     return X509at_get0_data_by_OBJ(si->signedAttrs, oid, lastpos, type);
82 }
83
84 int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si)
85 {
86     return X509at_get_attr_count(si->unsignedAttrs);
87 }
88
89 int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
90                                  int lastpos)
91 {
92     return X509at_get_attr_by_NID(si->unsignedAttrs, nid, lastpos);
93 }
94
95 int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si,
96                                  const ASN1_OBJECT *obj, int lastpos)
97 {
98     return X509at_get_attr_by_OBJ(si->unsignedAttrs, obj, lastpos);
99 }
100
101 X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc)
102 {
103     return X509at_get_attr(si->unsignedAttrs, loc);
104 }
105
106 X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc)
107 {
108     return X509at_delete_attr(si->unsignedAttrs, loc);
109 }
110
111 int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
112 {
113     if (X509at_add1_attr(&si->unsignedAttrs, attr))
114         return 1;
115     return 0;
116 }
117
118 int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
119                                   const ASN1_OBJECT *obj, int type,
120                                   const void *bytes, int len)
121 {
122     if (X509at_add1_attr_by_OBJ(&si->unsignedAttrs, obj, type, bytes, len))
123         return 1;
124     return 0;
125 }
126
127 int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
128                                   int nid, int type,
129                                   const void *bytes, int len)
130 {
131     if (X509at_add1_attr_by_NID(&si->unsignedAttrs, nid, type, bytes, len))
132         return 1;
133     return 0;
134 }
135
136 int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
137                                   const char *attrname, int type,
138                                   const void *bytes, int len)
139 {
140     if (X509at_add1_attr_by_txt(&si->unsignedAttrs, attrname,
141                                 type, bytes, len))
142         return 1;
143     return 0;
144 }
145
146 void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
147                                     int lastpos, int type)
148 {
149     return X509at_get0_data_by_OBJ(si->unsignedAttrs, oid, lastpos, type);
150 }
151
152 /* Specific attribute cases */