ossl_namemap_new.pod 3.7 KB

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