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 1282 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterSHA512()

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

Definition at line 1285 of file mlogger.cxx.

1286 {
1287 if (fTrace)
1288 printf("WriterSHA512: path [%s], level %d\n", log_chn->path.c_str(), level);
1289
1290 assert(wr != NULL);
1291
1292 fLevel = level;
1293 fWr = wr;
1294
1296 }
mbedtls_sha512_context fCtx
Definition mlogger.cxx:1415
WriterInterface * fWr
Definition mlogger.cxx:1414
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
void mbedtls_sha512_init(mbedtls_sha512_context *ctx)
Initialize SHA-512 context.
Definition sha512.cxx:141
Here is the call graph for this function:

◆ ~WriterSHA512()

WriterSHA512::~WriterSHA512 ( )
inline

Definition at line 1298 of file mlogger.cxx.

1299 {
1300 if (fTrace)
1301 printf("WriterSHA512: destructor\n");
1302 DELETE(fWr);
1303
1305 }
#define DELETE(ptr)
Definition mlogger.cxx:368
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 1349 of file mlogger.cxx.

1350 {
1351 char s[3];
1352 sprintf(s, "%02x", c);
1353 return s;
1354 }
char c
Definition system.cxx:1310
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

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

Definition at line 1356 of file mlogger.cxx.

1357 {
1358 std::string s;
1359 for (int i=0; i<64; i++)
1360 s += toHex(sha512sum[i]);
1361 return s;
1362 }
std::string toHex(unsigned char c)
Definition mlogger.cxx:1349
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 1364 of file mlogger.cxx.

1365 {
1366 std::string x = xpathname(log_chn->path.c_str(), fLevel);
1367 std::string f = x + ".sha512";
1368
1369 if (fTrace)
1370 printf("WriterSHA512: close path [%s], level %d, file [%s]\n", log_chn->path.c_str(), fLevel, f.c_str());
1371
1372 log_chn->handle = 0;
1373
1374 unsigned char sha512sum[64];
1376
1377 //std::string s = toString(sha512sum);
1378 //printf("sha512 %s\n", s.c_str());
1379
1380 cm_msg(MLOG, "SHA512", "File \'%s\' SHA-512 checksum: %s, %.0f bytes", x.c_str(), toString(sha512sum).c_str(), fBytesIn);
1381
1382 FILE *fp = fopen_wx(f.c_str());
1383 if (!fp) {
1384 cm_msg(MERROR, "WriterSHA512::wr_close", "Cannot write SHA-512 checksum to file \'%s\', fopen() errno %d (%s)", f.c_str(), errno, strerror(errno));
1385 } else {
1386 fprintf(fp, "%s %.0f %s\n", toString(sha512sum).c_str(), fBytesIn, x.c_str());
1387 fclose(fp);
1388 }
1389
1390 /* close downstream writer */
1391
1393
1394 fBytesIn += 0;
1396
1397 if (status != SUCCESS) {
1398 return status;
1399 }
1400
1401 return SUCCESS;
1402 }
virtual int wr_close(LOG_CHN *log_chn, int run_number)=0
std::string toString(const unsigned char sha512sum[64])
Definition mlogger.cxx:1356
#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:915
INT run_number[2]
Definition mana.cxx:246
static FILE * fopen_wx(const char *filename)
Definition mlogger.cxx:386
static std::string xpathname(const char *xpath, int level)
Definition mlogger.cxx:372
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
Here is the call graph for this function:

◆ wr_get_chain()

std::string WriterSHA512::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 1408 of file mlogger.cxx.

1408 {
1409 return "SHA512 | " + fWr->wr_get_chain();
1410 }
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 1404 of file mlogger.cxx.

1404 {
1405 return fWr->wr_get_file_ext();
1406 }
virtual std::string wr_get_file_ext()
Definition mlogger.cxx:414
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 1307 of file mlogger.cxx.

1308 {
1309 int status;
1310
1311 if (fTrace)
1312 printf("WriterSHA512: open path [%s], level %d\n", log_chn->path.c_str(), fLevel);
1313
1315
1316 fBytesIn += 0;
1318
1319 if (status != SUCCESS) {
1320 return status;
1321 }
1322
1323 log_chn->handle = 9999;
1324
1325 mbedtls_sha512_starts(&fCtx, 0); // 2nd argument selects 0=SHA-512 vs 1=SHA-384
1326
1327 return SUCCESS;
1328 }
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 1330 of file mlogger.cxx.

1331 {
1332 if (fTrace)
1333 printf("WriterSHA512: write path [%s], size %d\n", log_chn->path.c_str(), size);
1334
1335 mbedtls_sha512_update(&fCtx, (const unsigned char*)data, size);
1336
1337 int status = fWr->wr_write(log_chn, data, size);
1338
1339 fBytesIn += size;
1341
1342 if (status != SUCCESS) {
1343 return status;
1344 }
1345
1346 return SUCCESS;
1347 }
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 1415 of file mlogger.cxx.

◆ fLevel

int WriterSHA512::fLevel
private

Definition at line 1413 of file mlogger.cxx.

◆ fWr

WriterInterface* WriterSHA512::fWr
private

Definition at line 1414 of file mlogger.cxx.


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