ossl_namemap_new.pod 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. =pod
  2. =head1 NAME
  3. ossl_namemap_new, ossl_namemap_free, ossl_namemap_stored, ossl_namemap_empty,
  4. ossl_namemap_add_name, ossl_namemap_add_names,
  5. ossl_namemap_name2num, ossl_namemap_name2num_n,
  6. ossl_namemap_doall_names
  7. - internal number E<lt>-E<gt> name map
  8. =head1 SYNOPSIS
  9. #include "internal/cryptlib.h"
  10. OSSL_NAMEMAP *ossl_namemap_stored(OSSL_LIB_CTX *libctx);
  11. OSSL_NAMEMAP *ossl_namemap_new(void);
  12. void ossl_namemap_free(OSSL_NAMEMAP *namemap);
  13. int ossl_namemap_empty(OSSL_NAMEMAP *namemap);
  14. int ossl_namemap_add_name(OSSL_NAMEMAP *namemap, int number, const char *name);
  15. int ossl_namemap_name2num(const OSSL_NAMEMAP *namemap, const char *name);
  16. int ossl_namemap_name2num_n(const OSSL_NAMEMAP *namemap,
  17. const char *name, size_t name_len);
  18. int ossl_namemap_doall_names(const OSSL_NAMEMAP *namemap, int number,
  19. void (*fn)(const char *name, void *data),
  20. void *data);
  21. int ossl_namemap_add_names(OSSL_NAMEMAP *namemap, int number,
  22. const char *names, const char separator);
  23. =head1 DESCRIPTION
  24. A B<OSSL_NAMEMAP> is a one-to-many number E<lt>-E<gt> names map, which
  25. can be used to give any arbitrary set of names (any string) a unique
  26. dynamic identity that is valid throughout the lifetime of the associated
  27. library context.
  28. ossl_namemap_new() and ossl_namemap_free() construct and destruct a
  29. new B<OSSL_NAMEMAP>.
  30. This is suitable to use when the B<OSSL_NAMEMAP> is embedded in other
  31. structures, or should be independent for any reason.
  32. ossl_namemap_empty() checks if the given B<OSSL_NAMEMAP> is empty or
  33. not.
  34. ossl_namemap_stored() finds or auto-creates the default namemap in the
  35. given library context.
  36. The returned B<OSSL_NAMEMAP> can't be destructed using
  37. ossl_namemap_free().
  38. ossl_namemap_add_name() adds a new name to the namemap if it's not already
  39. present.
  40. If the given I<number> is zero, a new number will be allocated to
  41. identify this I<name>.
  42. If the given I<number> is nonzero, the I<name> is added to the set of
  43. names already associated with that number.
  44. ossl_namemap_name2num() finds the number corresponding to the given
  45. I<name>.
  46. ossl_namemap_name2num_n() does the same thing as
  47. ossl_namemap_name2num(), but takes a string length I<name_len> as well,
  48. allowing the caller to use a fragment of a string as a name.
  49. ossl_namemap_doall_names() walks through all names associated with
  50. I<number> in the given I<namemap> and calls the function I<fn> for
  51. each of them.
  52. I<fn> is also passed the I<data> argument, which allows any caller to
  53. pass extra data for that function to use.
  54. ossl_namemap_add_names() divides up a set of names given in I<names>,
  55. separated by I<separator>, and adds each to the I<namemap>, all with
  56. the same number. If some of them already exist in the I<namemap>,
  57. they must all have the same associated number, which will be adopted
  58. for any name that doesn't exist yet.
  59. =head1 RETURN VALUES
  60. ossl_namemap_new() and ossl_namemap_stored() return the pointer to a
  61. B<OSSL_NAMEMAP>, or NULL on error.
  62. ossl_namemap_empty() returns 1 if the B<OSSL_NAMEMAP> is NULL or
  63. empty, 0 if it's not empty, or -1 on internal error (such as inability
  64. to lock).
  65. ossl_namemap_add_name() returns the number associated with the added
  66. string, or zero on error.
  67. ossl_namemap_num2names() returns a pointer to a NULL-terminated list of
  68. pointers to the names corresponding to the given number, or NULL if
  69. it's undefined in the given B<OSSL_NAMEMAP>.
  70. ossl_namemap_name2num() and ossl_namemap_name2num_n() return the number
  71. corresponding to the given name, or 0 if it's undefined in the given
  72. B<OSSL_NAMEMAP>.
  73. ossl_namemap_doall_names() returns 1 if the callback was called for all names. A
  74. return value of 0 means that the callback was not called for any names.
  75. ossl_namemap_add_names() returns the number associated with the added
  76. names, or zero on error.
  77. =head1 NOTES
  78. The result from ossl_namemap_num2names() isn't thread safe, other threads
  79. dealing with the same namemap may cause the list of names to change
  80. location.
  81. It is therefore strongly recommended to only use the result in code
  82. guarded by a thread lock.
  83. =head1 HISTORY
  84. The functions described here were all added in OpenSSL 3.0.
  85. =head1 COPYRIGHT
  86. Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  87. Licensed under the Apache License 2.0 (the "License"). You may not use
  88. this file except in compliance with the License. You can obtain a copy
  89. in the file LICENSE in the source distribution or at
  90. L<https://www.openssl.org/source/license.html>.
  91. =cut