MCPcopy Create free account
hub / github.com/AGWA/git-crypt / load

Method load

key.cpp:52–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void Key_file::Entry::load (std::istream& in)
53{
54 while (true) {
55 uint32_t field_id;
56 if (!read_be32(in, field_id)) {
57 throw Malformed();
58 }
59 if (field_id == KEY_FIELD_END) {
60 break;
61 }
62 uint32_t field_len;
63 if (!read_be32(in, field_len)) {
64 throw Malformed();
65 }
66
67 if (field_id == KEY_FIELD_VERSION) {
68 if (field_len != 4) {
69 throw Malformed();
70 }
71 if (!read_be32(in, version)) {
72 throw Malformed();
73 }
74 } else if (field_id == KEY_FIELD_AES_KEY) {
75 if (field_len != AES_KEY_LEN) {
76 throw Malformed();
77 }
78 in.read(reinterpret_cast<char*>(aes_key), AES_KEY_LEN);
79 if (in.gcount() != AES_KEY_LEN) {
80 throw Malformed();
81 }
82 } else if (field_id == KEY_FIELD_HMAC_KEY) {
83 if (field_len != HMAC_KEY_LEN) {
84 throw Malformed();
85 }
86 in.read(reinterpret_cast<char*>(hmac_key), HMAC_KEY_LEN);
87 if (in.gcount() != HMAC_KEY_LEN) {
88 throw Malformed();
89 }
90 } else if (field_id & 1) { // unknown critical field
91 throw Incompatible();
92 } else {
93 // unknown non-critical field - safe to ignore
94 if (field_len > MAX_FIELD_LEN) {
95 throw Malformed();
96 }
97 in.ignore(field_len);
98 if (in.gcount() != static_cast<std::streamsize>(field_len)) {
99 throw Malformed();
100 }
101 }
102 }
103}
104
105void Key_file::Entry::load_legacy (uint32_t arg_version, std::istream& in)
106{

Callers 3

load_keyFunction · 0.80
decrypt_repo_keyFunction · 0.80
unlockFunction · 0.80

Calls 4

read_be32Function · 0.85
MalformedClass · 0.85
IncompatibleClass · 0.85
load_be32Function · 0.85

Tested by

no test coverage detected