| 43 | }; |
| 44 | |
| 45 | struct Key_file { |
| 46 | public: |
| 47 | struct Entry { |
| 48 | uint32_t version; |
| 49 | unsigned char aes_key[AES_KEY_LEN]; |
| 50 | unsigned char hmac_key[HMAC_KEY_LEN]; |
| 51 | |
| 52 | Entry (); |
| 53 | |
| 54 | void load (std::istream&); |
| 55 | void load_legacy (uint32_t version, std::istream&); |
| 56 | void store (std::ostream&) const; |
| 57 | void generate (uint32_t version); |
| 58 | }; |
| 59 | |
| 60 | struct Malformed { }; // exception class |
| 61 | struct Incompatible { }; // exception class |
| 62 | |
| 63 | const Entry* get_latest () const; |
| 64 | |
| 65 | const Entry* get (uint32_t version) const; |
| 66 | void add (const Entry&); |
| 67 | |
| 68 | void load_legacy (std::istream&); |
| 69 | void load (std::istream&); |
| 70 | void store (std::ostream&) const; |
| 71 | |
| 72 | bool load_from_file (const char* filename); |
| 73 | bool store_to_file (const char* filename) const; |
| 74 | |
| 75 | std::string store_to_string () const; |
| 76 | |
| 77 | void generate (); |
| 78 | |
| 79 | bool is_empty () const { return entries.empty(); } |
| 80 | bool is_filled () const { return !is_empty(); } |
| 81 | |
| 82 | uint32_t latest () const; |
| 83 | |
| 84 | void set_key_name (const char* k) { key_name = k ? k : ""; } |
| 85 | const char* get_key_name () const { return key_name.empty() ? 0 : key_name.c_str(); } |
| 86 | private: |
| 87 | typedef std::map<uint32_t, Entry, std::greater<uint32_t> > Map; |
| 88 | enum { FORMAT_VERSION = 2 }; |
| 89 | |
| 90 | Map entries; |
| 91 | std::string key_name; |
| 92 | |
| 93 | void load_header (std::istream&); |
| 94 | |
| 95 | enum { |
| 96 | HEADER_FIELD_END = 0, |
| 97 | HEADER_FIELD_KEY_NAME = 1 |
| 98 | }; |
| 99 | enum { |
| 100 | KEY_FIELD_END = 0, |
| 101 | KEY_FIELD_VERSION = 1, |
| 102 | KEY_FIELD_AES_KEY = 3, |
nothing calls this directly
no outgoing calls
no test coverage detected