X509_NAME_add_entry_by_txt.pod 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. =pod
  2. =head1 NAME
  3. X509_NAME_add_entry_by_txt, X509_NAME_add_entry_by_OBJ, X509_NAME_add_entry_by_NID,
  4. X509_NAME_add_entry, X509_NAME_delete_entry - X509_NAME modification functions
  5. =head1 SYNOPSIS
  6. #include <openssl/x509.h>
  7. int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,
  8. const unsigned char *bytes, int len, int loc, int set);
  9. int X509_NAME_add_entry_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, int type,
  10. const unsigned char *bytes, int len, int loc, int set);
  11. int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
  12. const unsigned char *bytes, int len, int loc, int set);
  13. int X509_NAME_add_entry(X509_NAME *name, const X509_NAME_ENTRY *ne, int loc, int set);
  14. X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
  15. =head1 DESCRIPTION
  16. X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ() and
  17. X509_NAME_add_entry_by_NID() add a field whose name is defined
  18. by a string B<field>, an object B<obj> or a NID B<nid> respectively.
  19. The field value to be added is in B<bytes> of length B<len>. If
  20. B<len> is -1 then the field length is calculated internally using
  21. strlen(bytes).
  22. The type of field is determined by B<type> which can either be a
  23. definition of the type of B<bytes> (such as B<MBSTRING_ASC>) or a
  24. standard ASN1 type (such as B<V_ASN1_IA5STRING>). The new entry is
  25. added to a position determined by B<loc> and B<set>.
  26. X509_NAME_add_entry() adds a copy of B<X509_NAME_ENTRY> structure B<ne>
  27. to B<name>. The new entry is added to a position determined by B<loc>
  28. and B<set>. Since a copy of B<ne> is added B<ne> must be freed up after
  29. the call.
  30. X509_NAME_delete_entry() deletes an entry from B<name> at position
  31. B<loc>. The deleted entry is returned and must be freed up.
  32. =head1 NOTES
  33. The use of string types such as B<MBSTRING_ASC> or B<MBSTRING_UTF8>
  34. is strongly recommended for the B<type> parameter. This allows the
  35. internal code to correctly determine the type of the field and to
  36. apply length checks according to the relevant standards. This is
  37. done using ASN1_STRING_set_by_NID().
  38. If instead an ASN1 type is used no checks are performed and the
  39. supplied data in B<bytes> is used directly.
  40. In X509_NAME_add_entry_by_txt() the B<field> string represents
  41. the field name using OBJ_txt2obj(field, 0).
  42. The B<loc> and B<set> parameters determine where a new entry should
  43. be added. For almost all applications B<loc> can be set to -1 and B<set>
  44. to 0. This adds a new entry to the end of B<name> as a single valued
  45. RelativeDistinguishedName (RDN).
  46. B<loc> actually determines the index where the new entry is inserted:
  47. if it is -1 it is appended.
  48. B<set> determines how the new type is added.
  49. If it is zero a new RDN is created.
  50. If B<set> is -1 or 1 it is added as a new set member
  51. to the previous or next RDN structure, respectively.
  52. This will then become part of a multi-valued RDN (containing a set of AVAs).
  53. Since multi-valued RDNs are very rarely used B<set> typically will be zero.
  54. =head1 RETURN VALUES
  55. X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ(),
  56. X509_NAME_add_entry_by_NID() and X509_NAME_add_entry() return 1 for
  57. success of 0 if an error occurred.
  58. X509_NAME_delete_entry() returns either the deleted B<X509_NAME_ENTRY>
  59. structure or B<NULL> if an error occurred.
  60. =head1 EXAMPLES
  61. Create an B<X509_NAME> structure:
  62. "C=UK, O=Disorganized Organization, CN=Joe Bloggs"
  63. X509_NAME *nm;
  64. nm = X509_NAME_new();
  65. if (nm == NULL)
  66. /* Some error */
  67. if (!X509_NAME_add_entry_by_txt(nm, "C", MBSTRING_ASC,
  68. "UK", -1, -1, 0))
  69. /* Error */
  70. if (!X509_NAME_add_entry_by_txt(nm, "O", MBSTRING_ASC,
  71. "Disorganized Organization", -1, -1, 0))
  72. /* Error */
  73. if (!X509_NAME_add_entry_by_txt(nm, "CN", MBSTRING_ASC,
  74. "Joe Bloggs", -1, -1, 0))
  75. /* Error */
  76. =head1 BUGS
  77. B<type> can still be set to B<V_ASN1_APP_CHOOSE> to use a
  78. different algorithm to determine field types. Since this form does
  79. not understand multicharacter types, performs no length checks and
  80. can result in invalid field types its use is strongly discouraged.
  81. =head1 SEE ALSO
  82. L<ERR_get_error(3)>, L<d2i_X509_NAME(3)>
  83. =head1 COPYRIGHT
  84. Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
  85. Licensed under the Apache License 2.0 (the "License"). You may not use
  86. this file except in compliance with the License. You can obtain a copy
  87. in the file LICENSE in the source distribution or at
  88. L<https://www.openssl.org/source/license.html>.
  89. =cut