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