MIDAS
Loading...
Searching...
No Matches
WriterSHA512 Class Reference
Inheritance diagram for WriterSHA512:
Collaboration diagram for WriterSHA512:

Public Member Functions

 WriterSHA512 (LOG_CHN *log_chn, int level, WriterInterface *wr)
 
 ~WriterSHA512 ()
 
int wr_open (LOG_CHN *log_chn, int run_number)
 
int wr_write (LOG_CHN *log_chn, const void *data, const int size)
 
std::string toHex (unsigned char c)
 
std::string toString (const unsigned char sha512sum[64])
 
int wr_close (LOG_CHN *log_chn, int run_number)
 
std::string wr_get_file_ext ()
 
std::string wr_get_chain ()
 
- Public Member Functions inherited from WriterInterface
 WriterInterface ()
 
virtual ~WriterInterface ()
 

Private Attributes

int fLevel
 
WriterInterfacefWr
 
mbedtls_sha512_context fCtx
 

Additional Inherited Members

- Public Attributes inherited from WriterInterface
bool fTrace
 
double fBytesIn
 
double fBytesOut
 

Detailed Description

Definition at line 1256 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterSHA512()

WriterSHA512::WriterSHA512 ( LOG_CHN log_chn,
int  level,
WriterInterface wr 
)
inline

Definition at line 1259 of file mlogger.cxx.

1260 {
1261 if (fTrace)
1262 printf("WriterSHA512: path [%s], level %d\n", log_chn->path.c_str(), level);
1263
1264 assert(wr != NULL);
1265
1266 fLevel = level;
1267 fWr = wr;
1268
1270 }
mbedtls_sha512_context fCtx
Definition mlogger.cxx:1389
WriterInterface * fWr
Definition mlogger.cxx:1388
void mbedtls_sha512_init(mbedtls_sha512_context *ctx)
Initialize SHA-512 context.
Definition sha512.cxx:141
std::string path
Definition mlogger.cxx:250
Here is the call graph for this function:

◆ ~WriterSHA512()

WriterSHA512::~WriterSHA512 ( )
inline

Definition at line 1272 of file mlogger.cxx.

1273 {
1274 if (fTrace)
1275 printf("WriterSHA512: destructor\n");
1276 DELETE(fWr);
1277
1279 }
#define DELETE(ptr)
Definition mlogger.cxx:342
void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
Clear SHA-512 context.
Definition sha512.cxx:146
Here is the call graph for this function:

Member Function Documentation

◆ toHex()

std::string WriterSHA512::toHex ( unsigned char  c)
inline

Definition at line 1323 of file mlogger.cxx.

1324 {
1325 char s[3];
1326 sprintf(s, "%02x", c);
1327 return s;
1328 }
char c
Definition system.cxx:1312
Here is the caller graph for this function:

◆ toString()

std::string WriterSHA512::toString ( const unsigned char  sha512sum[64])
inline

Definition at line 1330 of file mlogger.cxx.

1331 {
1332 std::string s;
1333 for (int i=0; i<64; i++)
1334 s += toHex(sha512sum[i]);
1335 return s;
1336 }
std::string toHex(unsigned char c)
Definition mlogger.cxx:1323
INT i
Definition mdump.cxx:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wr_close()

int WriterSHA512::wr_close ( LOG_CHN log_chn,
int  run_number 
)
inlinevirtual

Implements WriterInterface.

Definition at line 1338 of file mlogger.cxx.

1339 {
1340 std::string x = xpathname(log_chn->path.c_str(), fLevel);
1341 std::string f = x + ".sha512";
1342
1343 if (fTrace)
1344 printf("WriterSHA512: close path [%s], level %d, file [%s]\n", log_chn->path.c_str(), fLevel, f.c_str());
1345
1346 log_chn->handle = 0;
1347
1348 unsigned char sha512sum[64];
1349 mbedtls_sha512_finish(&fCtx, sha512sum);
1350
1351 //std::string s = toString(sha512sum);
1352 //printf("sha512 %s\n", s.c_str());
1353
1354 cm_msg(MLOG, "SHA512", "File \'%s\' SHA-512 checksum: %s, %.0f bytes", x.c_str(), toString(sha512sum).c_str(), fBytesIn);
1355
1356 FILE *fp = fopen_wx(f.c_str());
1357 if (!fp) {
1358 cm_msg(MERROR, "WriterSHA512::wr_close", "Cannot write SHA-512 checksum to file \'%s\', fopen() errno %d (%s)", f.c_str(), errno, strerror(errno));
1359 } else {
1360 fprintf(fp, "%s %.0f %s\n", toString(sha512sum).c_str(), fBytesIn, x.c_str());
1361 fclose(fp);
1362 }
1363
1364 /* close downstream writer */
1365
1366 int status = fWr->wr_close(log_chn, run_number);
1367
1368 fBytesIn += 0;
1370
1371 if (status != SUCCESS) {
1372 return status;
1373 }
1374
1375 return SUCCESS;
1376 }
virtual int wr_close(LOG_CHN *log_chn, int run_number)=0
std::string toString(const unsigned char sha512sum[64])
Definition mlogger.cxx:1330
#define SUCCESS
Definition mcstd.h:54
#define MLOG
Definition midas.h:563
#define MERROR
Definition midas.h:559
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:931
INT run_number[2]
Definition mana.cxx:246
static FILE * fopen_wx(const char *filename)
Definition mlogger.cxx:360
static std::string xpathname(const char *xpath, int level)
Definition mlogger.cxx:346
static FILE * fp
DWORD status
Definition odbhist.cxx:39
void mbedtls_sha512_finish(mbedtls_sha512_context *ctx, unsigned char output[64])
SHA-512 final digest.
Definition sha512.cxx:322
INT handle
Definition mlogger.cxx:249
Here is the call graph for this function:

◆ wr_get_chain()

std::string WriterSHA512::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 1382 of file mlogger.cxx.

1382 {
1383 return "SHA512 | " + fWr->wr_get_chain();
1384 }
virtual std::string wr_get_chain()=0
Here is the call graph for this function:

◆ wr_get_file_ext()

std::string WriterSHA512::wr_get_file_ext ( )
inlinevirtual

Reimplemented from WriterInterface.

Definition at line 1378 of file mlogger.cxx.

1378 {
1379 return fWr->wr_get_file_ext();
1380 }
virtual std::string wr_get_file_ext()
Definition mlogger.cxx:388
Here is the call graph for this function:

◆ wr_open()

int WriterSHA512::wr_open ( LOG_CHN log_chn,
int  run_number 
)
inlinevirtual

Implements WriterInterface.

Definition at line 1281 of file mlogger.cxx.

1282 {
1283 int status;
1284
1285 if (fTrace)
1286 printf("WriterSHA512: open path [%s], level %d\n", log_chn->path.c_str(), fLevel);
1287
1288 status = fWr->wr_open(log_chn, run_number);
1289
1290 fBytesIn += 0;
1292
1293 if (status != SUCCESS) {
1294 return status;
1295 }
1296
1297 log_chn->handle = 9999;
1298
1299 mbedtls_sha512_starts(&fCtx, 0); // 2nd argument selects 0=SHA-512 vs 1=SHA-384
1300
1301 return SUCCESS;
1302 }
virtual int wr_open(LOG_CHN *log_chn, int run_number)=0
void mbedtls_sha512_starts(mbedtls_sha512_context *ctx, int is384)
SHA-512 context setup.
Definition sha512.cxx:163
Here is the call graph for this function:

◆ wr_write()

int WriterSHA512::wr_write ( LOG_CHN log_chn,
const void *  data,
const int  size 
)
inlinevirtual

Implements WriterInterface.

Definition at line 1304 of file mlogger.cxx.

1305 {
1306 if (fTrace)
1307 printf("WriterSHA512: write path [%s], size %d\n", log_chn->path.c_str(), size);
1308
1309 mbedtls_sha512_update(&fCtx, (const unsigned char*)data, size);
1310
1311 int status = fWr->wr_write(log_chn, data, size);
1312
1313 fBytesIn += size;
1315
1316 if (status != SUCCESS) {
1317 return status;
1318 }
1319
1320 return SUCCESS;
1321 }
virtual int wr_write(LOG_CHN *log_chn, const void *data, const int size)=0
void * data
Definition mana.cxx:268
void mbedtls_sha512_update(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
SHA-512 process buffer.
Definition sha512.cxx:270
Here is the call graph for this function:

Member Data Documentation

◆ fCtx

mbedtls_sha512_context WriterSHA512::fCtx
private

Definition at line 1389 of file mlogger.cxx.

◆ fLevel

int WriterSHA512::fLevel
private

Definition at line 1387 of file mlogger.cxx.

◆ fWr

WriterInterface* WriterSHA512::fWr
private

Definition at line 1388 of file mlogger.cxx.


The documentation for this class was generated from the following file: