275d96aeb22ceb406609c3fade25fbfab0e670a9
[aaf/sshsm.git] / TPM2-Plugin / lib / include / tpm2_convert.h
1 //**********************************************************************;
2 // Copyright (c) 2017, SUSE GmbH
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 // THE POSSIBILITY OF SUCH DAMAGE.
26 //**********************************************************************;
27
28 #ifndef CONVERSION_H
29 #define CONVERSION_H
30
31 #include <stdbool.h>
32
33 #include <tss2/tss2_sys.h>
34
35 typedef enum tpm2_convert_pubkey_fmt tpm2_convert_pubkey_fmt;
36 enum tpm2_convert_pubkey_fmt {
37     pubkey_format_tss,
38     pubkey_format_pem,
39     pubkey_format_der,
40     pubkey_format_err
41 };
42
43 typedef enum tpm2_convert_sig_fmt tpm2_convert_sig_fmt;
44 enum tpm2_convert_sig_fmt {
45     signature_format_tss,
46     signature_format_plain,
47     signature_format_err
48 };
49
50 /**
51  * Parses the given command line public key format option string and returns
52  * the corresponding pubkey_format enum value.
53  *
54  * LOG_ERR is used to communicate errors.
55  *
56  * @return
57  *   On error pubkey_format_err is returned.
58  */
59 tpm2_convert_pubkey_fmt tpm2_convert_pubkey_fmt_from_optarg(const char *label);
60
61 /**
62  * Converts the given public key structure into the requested target format
63  * and writes the result to the given file system path.
64  *
65  * LOG_ERR is used to communicate errors.
66  */
67 bool tpm2_convert_pubkey_save(TPM2B_PUBLIC *public, tpm2_convert_pubkey_fmt format, const char *path);
68
69 /**
70  * Loads a public key in the TSS format from a file.
71  * @param public
72  *  The public key to load
73  * @param format
74  * @param path
75  * @return
76  */
77 bool tpm2_convert_pubkey_load(TPM2B_PUBLIC *public, const char *path);
78
79 /**
80  * Parses the given command line signature format option string and returns
81  * the corresponding signature_format enum value.
82  *
83  * LOG_ERR is used to communicate errors.
84  *
85  * @return
86  *   On error signature_format_err is returned.
87  */
88 tpm2_convert_sig_fmt tpm2_convert_sig_fmt_from_optarg(const char *label);
89
90 /**
91  * Converts the given signature data into the requested target format and
92  * writes the result to the given file system path.
93  *
94  * LOG_ERR is used to communicate errors.
95  */
96 bool tpm2_convert_sig(TPMT_SIGNATURE *signature, tpm2_convert_sig_fmt format,
97         const char *path);
98
99 #endif /* CONVERSION_H */