multicert.c 884 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <config.h>
  2. #include "openconnect-internal.h"
  3. static const struct {
  4. openconnect_hash_type id;
  5. const char *name;
  6. } digest_table[OPENCONNECT_HASH_MAX + 1] = {
  7. [ OPENCONNECT_HASH_SHA256 ] = { OPENCONNECT_HASH_SHA256, "sha256" },
  8. [ OPENCONNECT_HASH_SHA384 ] = { OPENCONNECT_HASH_SHA384, "sha384" },
  9. [ OPENCONNECT_HASH_SHA512 ] = { OPENCONNECT_HASH_SHA512, "sha512" },
  10. };
  11. const char *multicert_hash_get_name(int id)
  12. {
  13. size_t i;
  14. if (id > 0 && (size_t) id < ARRAY_SIZE(digest_table)) {
  15. i = (size_t) id;
  16. if (digest_table[i].id)
  17. return digest_table[i].name;
  18. }
  19. return NULL;
  20. }
  21. openconnect_hash_type multicert_hash_get_id(const char *name)
  22. {
  23. size_t i;
  24. if (name) {
  25. for (i = 1; i < ARRAY_SIZE(digest_table); i++) {
  26. if (digest_table[i].name &&
  27. !strcmp(digest_table[i].name, name))
  28. return digest_table[i].id;
  29. }
  30. }
  31. return OPENCONNECT_HASH_UNKNOWN;
  32. }