2
0

cms_att.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. #include <openssl/asn1t.h>
  10. #include <openssl/pem.h>
  11. #include <openssl/x509v3.h>
  12. #include <openssl/err.h>
  13. #include <openssl/cms.h>
  14. #include "cms_lcl.h"
  15. /* CMS SignedData Attribute utilities */
  16. int CMS_signed_get_attr_count(const CMS_SignerInfo *si)
  17. {
  18. return X509at_get_attr_count(si->signedAttrs);
  19. }
  20. int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, int lastpos)
  21. {
  22. return X509at_get_attr_by_NID(si->signedAttrs, nid, lastpos);
  23. }
  24. int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
  25. int lastpos)
  26. {
  27. return X509at_get_attr_by_OBJ(si->signedAttrs, obj, lastpos);
  28. }
  29. X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc)
  30. {
  31. return X509at_get_attr(si->signedAttrs, loc);
  32. }
  33. X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc)
  34. {
  35. return X509at_delete_attr(si->signedAttrs, loc);
  36. }
  37. int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
  38. {
  39. if (X509at_add1_attr(&si->signedAttrs, attr))
  40. return 1;
  41. return 0;
  42. }
  43. int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
  44. const ASN1_OBJECT *obj, int type,
  45. const void *bytes, int len)
  46. {
  47. if (X509at_add1_attr_by_OBJ(&si->signedAttrs, obj, type, bytes, len))
  48. return 1;
  49. return 0;
  50. }
  51. int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
  52. int nid, int type, const void *bytes, int len)
  53. {
  54. if (X509at_add1_attr_by_NID(&si->signedAttrs, nid, type, bytes, len))
  55. return 1;
  56. return 0;
  57. }
  58. int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
  59. const char *attrname, int type,
  60. const void *bytes, int len)
  61. {
  62. if (X509at_add1_attr_by_txt(&si->signedAttrs, attrname, type, bytes, len))
  63. return 1;
  64. return 0;
  65. }
  66. void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *oid,
  67. int lastpos, int type)
  68. {
  69. return X509at_get0_data_by_OBJ(si->signedAttrs, oid, lastpos, type);
  70. }
  71. int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si)
  72. {
  73. return X509at_get_attr_count(si->unsignedAttrs);
  74. }
  75. int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
  76. int lastpos)
  77. {
  78. return X509at_get_attr_by_NID(si->unsignedAttrs, nid, lastpos);
  79. }
  80. int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si,
  81. const ASN1_OBJECT *obj, int lastpos)
  82. {
  83. return X509at_get_attr_by_OBJ(si->unsignedAttrs, obj, lastpos);
  84. }
  85. X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc)
  86. {
  87. return X509at_get_attr(si->unsignedAttrs, loc);
  88. }
  89. X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc)
  90. {
  91. return X509at_delete_attr(si->unsignedAttrs, loc);
  92. }
  93. int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
  94. {
  95. if (X509at_add1_attr(&si->unsignedAttrs, attr))
  96. return 1;
  97. return 0;
  98. }
  99. int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
  100. const ASN1_OBJECT *obj, int type,
  101. const void *bytes, int len)
  102. {
  103. if (X509at_add1_attr_by_OBJ(&si->unsignedAttrs, obj, type, bytes, len))
  104. return 1;
  105. return 0;
  106. }
  107. int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
  108. int nid, int type,
  109. const void *bytes, int len)
  110. {
  111. if (X509at_add1_attr_by_NID(&si->unsignedAttrs, nid, type, bytes, len))
  112. return 1;
  113. return 0;
  114. }
  115. int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
  116. const char *attrname, int type,
  117. const void *bytes, int len)
  118. {
  119. if (X509at_add1_attr_by_txt(&si->unsignedAttrs, attrname,
  120. type, bytes, len))
  121. return 1;
  122. return 0;
  123. }
  124. void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
  125. int lastpos, int type)
  126. {
  127. return X509at_get0_data_by_OBJ(si->unsignedAttrs, oid, lastpos, type);
  128. }
  129. /* Specific attribute cases */