MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / ReadMem

Method ReadMem

src/twcrypto/keyfile.cpp:266–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264// exception if keys are not currently loaded.
265
266void cKeyFile::ReadMem(const int8* pMem) // throw eKeyFile()
267{
268 int16 i16;
269 int32 i32;
270
271 ReleaseMem();
272
273 memcpy(&i32, pMem, sizeof(i32));
274 if ((unsigned int)tw_ntohl(i32) != KEY_MAGIC_NUMBER)
275 throw eKeyFileInvalidFmt();
276 pMem += sizeof(int32);
277
278 memcpy(&i32, pMem, sizeof(i32));
279 if (tw_ntohl(i32) != 1) // version check
280 throw eKeyFileInvalidFmt();
281 pMem += sizeof(int32);
282
283 memcpy(&i16, pMem, sizeof(i16));
284 int16 len = tw_ntohs(i16);
285 if (len <= 0 || len > 9000)
286 {
287 ASSERT(false);
288 throw eKeyFileInvalidFmt();
289 }
290
291 mpPublicKey = new cElGamalSigPublicKey((void*)(pMem + sizeof(int16)));
292 pMem += sizeof(int16) + len;
293
294 memcpy(&i16, pMem, sizeof(i16));
295 mPrivateKeyMemLen = tw_ntohs(i16);
296 if (mPrivateKeyMemLen <= 0 || mPrivateKeyMemLen > 9000)
297 {
298 ASSERT(false);
299 delete mpPublicKey;
300 mpPublicKey = 0;
301 throw eKeyFileInvalidFmt();
302 }
303
304 mpPrivateKeyMem = new int8[mPrivateKeyMemLen];
305 memcpy(mpPrivateKeyMem, pMem + sizeof(int16), mPrivateKeyMemLen);
306}
307
308void cKeyFile::WriteMem(int8* pMem) const // throw eKeyFile()
309{

Callers 2

GenerateKeyFunction · 0.80
TestKeyFileFunction · 0.80

Calls

no outgoing calls

Tested by 1

TestKeyFileFunction · 0.64