EVP_PKEY_is_a.pod 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_is_a, EVP_PKEY_can_sign
  4. - key type and capabilities functions
  5. =head1 SYNOPSIS
  6. #include <openssl/evp.h>
  7. int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name);
  8. int EVP_PKEY_can_sign(const EVP_PKEY *pkey);
  9. =head1 DESCRIPTION
  10. EVP_PKEY_is_a() checks if the key type of I<pkey> is I<name>.
  11. EVP_PKEY_can_sign() checks if the functionality for the key type of
  12. I<pkey> supports signing. No other check is done, such as whether
  13. I<pkey> contains a private key.
  14. =head1 RETURN VALUES
  15. EVP_PKEY_is_a() returns 1 if I<pkey> has the key type I<name>,
  16. otherwise 0.
  17. EVP_PKEY_can_sign() returns 1 if the I<pkey> key type functionality
  18. supports signing, otherwise 0.
  19. =head1 EXAMPLES
  20. =head2 EVP_PKEY_is_a()
  21. The loaded providers and what key types they support will ultimately
  22. determine what I<name> is possible to use with EVP_PKEY_is_a(). We do know
  23. that the default provider supports RSA, DH, DSA and EC keys, so we can use
  24. this as an crude example:
  25. #include <openssl/evp.h>
  26. ...
  27. /* |pkey| is an EVP_PKEY* */
  28. if (EVP_PKEY_is_a(pkey, "RSA")) {
  29. BIGNUM *modulus = NULL;
  30. if (EVP_PKEY_get_bn_param(pkey, "n", &modulus))
  31. /* do whatever with the modulus */
  32. BN_free(modulus);
  33. }
  34. =head2 EVP_PKEY_can_sign()
  35. #include <openssl/evp.h>
  36. ...
  37. /* |pkey| is an EVP_PKEY* */
  38. if (!EVP_PKEY_can_sign(pkey)) {
  39. fprintf(stderr, "Not a signing key!");
  40. exit(1);
  41. }
  42. /* Sign something... */
  43. =head1 COPYRIGHT
  44. Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
  45. Licensed under the Apache License 2.0 (the "License"). You may not use
  46. this file except in compliance with the License. You can obtain a copy
  47. in the file LICENSE in the source distribution or at
  48. L<https://www.openssl.org/source/license.html>.
  49. =cut