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

Function WriteObjectToArchive

src/tw/twutil.cpp:91–143  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// WriteObjectToArchive -- called from WriteObject, does most of the work //////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

89// WriteObjectToArchive -- called from WriteObject, does most of the work
90///////////////////////////////////////////////////////////////////////////////
91static void WriteObjectToArchive(cArchive& arch,
92 const TCHAR* filename, // filename is used only for issuing error messages
93 const iTypedSerializable* pObjHeader,
94 const iTypedSerializable& obj,
95 cFileHeader& fileHeader,
96 bool bEncrypt,
97 const cElGamalSigPrivateKey* pPrivateKey)
98{
99 try
100 {
101 // Set file version.
102 // If we in the future we wish to support reading databases of different versions,
103 // we will have to move this set to outside WriteObject().
104 fileHeader.SetVersion(CURRENT_FIXED_VERSION);
105
106 fileHeader.SetEncoding(bEncrypt ? cFileHeader::ASYM_ENCRYPTION : cFileHeader::COMPRESSED);
107
108 {
109 cSerializerImpl fhSer(arch, cSerializerImpl::S_WRITE, filename);
110 fileHeader.Write(&fhSer);
111 }
112
113 if (bEncrypt)
114 {
115 cElGamalSigArchive cryptoArchive;
116 cryptoArchive.SetWrite(&arch, pPrivateKey);
117 cSerializerImpl ser(cryptoArchive, cSerializerImpl::S_WRITE, filename);
118 ser.Init();
119 if (pObjHeader)
120 ser.WriteObject(pObjHeader);
121 ser.WriteObject(&obj);
122 ser.Finit();
123 cryptoArchive.FlushWrite();
124 }
125 else
126 {
127 // not encrypted
128 cNullCryptoArchive cryptoArchive;
129 cryptoArchive.Start(&arch);
130 cSerializerImpl ser(cryptoArchive, cSerializerImpl::S_WRITE, filename);
131 ser.Init();
132 if (pObjHeader)
133 ser.WriteObject(pObjHeader);
134 ser.WriteObject(&obj);
135 ser.Finit();
136 cryptoArchive.Finish();
137 }
138 }
139 catch (eError& e)
140 {
141 throw ePoly(e.GetID(), cErrorUtil::MakeFileError(e.GetMsg(), filename), e.GetFlags());
142 }
143}
144
145///////////////////////////////////////////////////////////////////////////////
146// WriteObject -- template class that writes an object to disk (ie -- report,

Callers 1

WriteObjectFunction · 0.85

Calls 14

ePolyClass · 0.85
SetVersionMethod · 0.80
SetEncodingMethod · 0.80
SetWriteMethod · 0.80
WriteObjectMethod · 0.80
FlushWriteMethod · 0.80
FinishMethod · 0.80
GetIDMethod · 0.80
GetFlagsMethod · 0.80
WriteMethod · 0.45
InitMethod · 0.45
FinitMethod · 0.45

Tested by

no test coverage detected