1 /* 2 Copyright 2021 Northern.tech AS 3 4 This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License as published by the 8 Free Software Foundation; version 3. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 19 To the extent this program is licensed as part of the Enterprise 20 versions of CFEngine, the applicable Commercial Open Source License 21 (COSL) may apply to this file if you as a licensee so wish it. See 22 included file COSL.txt. 23 */ 24 25 #ifndef KEY_H 26 #define KEY_H 27 28 #include <openssl/rsa.h> 29 30 #include <hash.h> 31 32 33 /** 34 @brief Structure to simplify the key management. 35 36 */ 37 typedef struct Key Key; 38 39 /** 40 @brief Creates a new Key structure. 41 @param key RSA structure 42 @param hash Hash method to use when hashing the key. 43 @return A fully initialized Key structure or NULL in case of error. 44 */ 45 Key *KeyNew(RSA *rsa, HashMethod method); 46 /** 47 @brief Destroys a structure of type Key. 48 @param key Structure to be destroyed. 49 */ 50 void KeyDestroy(Key **key); 51 /** 52 @brief Constant pointer to the key data. 53 @param key Key 54 @return A pointer to the RSA structure. 55 */ 56 RSA *KeyRSA(const Key *key); 57 /** 58 @brief Binary hash of the key 59 @param key Key structure 60 @param length Length of the binary hash 61 @return A pointer to the binary hash or NULL in case of error. 62 */ 63 const unsigned char *KeyBinaryHash(const Key *key, unsigned int *length); 64 /** 65 @brief Printable hash of the key. 66 @param key 67 @return A pointer to the printable hash of the key. 68 */ 69 const char *KeyPrintableHash(const Key *key); 70 /** 71 @brief Method use to hash the key. 72 @param key Structure 73 @return Method used to hash the key. 74 */ 75 HashMethod KeyHashMethod(const Key *key); 76 /** 77 @brief Changes the method used to hash the key. 78 79 This method triggers a rehashing of the key. This can be an expensive operation. 80 @param key Structure 81 @param hash New hashing mechanism. 82 @return 0 if successful, -1 in case of error. 83 */ 84 int KeySetHashMethod(Key *key, HashMethod method); 85 /** 86 @brief Internal Hash data 87 @param key Structure 88 @return A pointer to the Hash structure or NULL in case of error. 89 */ 90 const Hash *KeyData(Key *key); 91 92 #endif // KEY_H 93