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

Method WriteFile

src/twcrypto/keyfile.cpp:217–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217void cKeyFile::WriteFile(const TCHAR* filename) const // throw eKeyFile()
218{
219 ASSERT(KeysLoaded());
220
221 try
222 {
223 cFileArchive outFile;
224 cFileHeader fileHeader;
225
226 outFile.OpenReadWrite(filename);
227
228 fileHeader.SetID(cKeyFile::GetFileHeaderID());
229
230 // Set file version.
231 // If we in the future we wish to support reading keys different versions,
232 // we will have to move this
233 fileHeader.SetVersion(CURRENT_FIXED_VERSION);
234
235 fileHeader.SetEncoding(cFileHeader::NO_ENCODING);
236
237 {
238 cSerializerImpl fhSer(outFile, cSerializerImpl::S_WRITE, filename);
239 fileHeader.Write(&fhSer);
240 }
241
242 // save public key
243 int16 len = mpPublicKey->GetWriteLen();
244 int8* publicMem = new int8[len];
245 mpPublicKey->Write(publicMem);
246
247 outFile.WriteInt16(len);
248 outFile.WriteBlob(publicMem, len);
249
250 delete [] publicMem;
251
252 // save private key
253 len = mPrivateKeyMemLen;
254 outFile.WriteInt16(len);
255 outFile.WriteBlob(mpPrivateKeyMem, mPrivateKeyMemLen);
256 }
257 catch (eArchive&)
258 {
259 throw eKeyFileArchive(filename);
260 }
261}
262
263// Functions to read and write the key to memory. GetWriteLen() will throw an
264// exception if keys are not currently loaded.

Callers 3

ChangePassphraseFunction · 0.80
TestKeyFileFunction · 0.80

Calls 8

OpenReadWriteMethod · 0.80
SetVersionMethod · 0.80
SetEncodingMethod · 0.80
SetIDMethod · 0.45
WriteMethod · 0.45
GetWriteLenMethod · 0.45
WriteInt16Method · 0.45
WriteBlobMethod · 0.45

Tested by 1

TestKeyFileFunction · 0.64