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

Public Member Functions

 WriterSHA256 (LOG_CHN *log_chn, int level, WriterInterface *wr)
 
 ~WriterSHA256 ()
 
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 sha256sum[32])
 
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_sha256_context fCtx
 

Additional Inherited Members

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

Detailed Description

Definition at line 1116 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterSHA256()

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

Definition at line 1119 of file mlogger.cxx.

1120 {
1121 if (fTrace)
1122 printf("WriterSHA256: path [%s], level %d\n", log_chn->path.c_str(), level);
1123
1124 assert(wr != NULL);
1125
1126 fLevel = level;
1127 fWr = wr;
1128
1130 }
mbedtls_sha256_context fCtx
Definition mlogger.cxx:1249
WriterInterface * fWr
Definition mlogger.cxx:1248
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
Initialize SHA-256 context.
Definition sha256.cxx:80
std::string path
Definition mlogger.cxx:250
Here is the call graph for this function:

◆ ~WriterSHA256()

WriterSHA256::~WriterSHA256 ( )
inline

Definition at line 1132 of file mlogger.cxx.

1133 {
1134 if (fTrace)
1135 printf("WriterSHA256: destructor\n");
1136 DELETE(fWr);
1137
1139 }
#define DELETE(ptr)
Definition mlogger.cxx:342
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
Clear SHA-256 context.
Definition sha256.cxx:85
Here is the call graph for this function:

Member Function Documentation

◆ toHex()

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

Definition at line 1183 of file mlogger.cxx.

1184 {
1185 char s[3];
1186 sprintf(s, "%02x", c);
1187 return s;
1188 }
char c
Definition system.cxx:1312
Here is the caller graph for this function:

◆ toString()

std::string WriterSHA256::toString ( const unsigned char  sha256sum[32])
inline

Definition at line 1190 of file mlogger.cxx.

1191 {
1192 std::string s;
1193 for (int i=0; i<32; i++)
1194 s += toHex(sha256sum[i]);
1195 return s;
1196 }
std::string toHex(unsigned char c)
Definition mlogger.cxx:1183
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 WriterSHA256::wr_close ( LOG_CHN log_chn,
int  run_number 
)
inlinevirtual

Implements WriterInterface.

Definition at line 1198 of file mlogger.cxx.

1199 {
1200 std::string x = xpathname(log_chn->path.c_str(), fLevel);
1201 std::string f = x + ".sha256";
1202
1203 if (fTrace)
1204 printf("WriterSHA256: close path [%s], level %d, file [%s]\n", log_chn->path.c_str(), fLevel, f.c_str());
1205
1206 log_chn->handle = 0;
1207
1208 unsigned char sha256sum[32];
1209 mbedtls_sha256_finish(&fCtx, sha256sum);
1210
1211 //std::string s = toString(sha256sum);
1212 //printf("sha256 %s\n", s.c_str());
1213
1214 cm_msg(MLOG, "SHA256", "File \'%s\' SHA-256 checksum: %s, %.0f bytes", x.c_str(), toString(sha256sum).c_str(), fBytesIn);
1215
1216 FILE *fp = fopen_wx(f.c_str());
1217 if (!fp) {
1218 cm_msg(MERROR, "WriterSHA256::wr_close", "Cannot write SHA-256 checksum to file \'%s\', fopen() errno %d (%s)", f.c_str(), errno, strerror(errno));
1219 } else {
1220 fprintf(fp, "%s %.0f %s\n", toString(sha256sum).c_str(), fBytesIn, x.c_str());
1221 fclose(fp);
1222 }
1223
1224 /* close downstream writer */
1225
1226 int status = fWr->wr_close(log_chn, run_number);
1227
1228 fBytesIn += 0;
1230
1231 if (status != SUCCESS) {
1232 return status;
1233 }
1234
1235 return SUCCESS;
1236 }
virtual int wr_close(LOG_CHN *log_chn, int run_number)=0
std::string toString(const unsigned char sha256sum[32])
Definition mlogger.cxx:1190
#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_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
SHA-256 final digest.
Definition sha256.cxx:289
INT handle
Definition mlogger.cxx:249
Here is the call graph for this function:

◆ wr_get_chain()

std::string WriterSHA256::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 1242 of file mlogger.cxx.

1242 {
1243 return "SHA256 | " + fWr->wr_get_chain();
1244 }
virtual std::string wr_get_chain()=0
Here is the call graph for this function:

◆ wr_get_file_ext()

std::string WriterSHA256::wr_get_file_ext ( )
inlinevirtual

Reimplemented from WriterInterface.

Definition at line 1238 of file mlogger.cxx.

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

◆ wr_open()

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

Implements WriterInterface.

Definition at line 1141 of file mlogger.cxx.

1142 {
1143 int status;
1144
1145 if (fTrace)
1146 printf("WriterSHA256: open path [%s], level %d\n", log_chn->path.c_str(), fLevel);
1147
1148 status = fWr->wr_open(log_chn, run_number);
1149
1150 fBytesIn += 0;
1152
1153 if (status != SUCCESS) {
1154 return status;
1155 }
1156
1157 log_chn->handle = 9999;
1158
1159 mbedtls_sha256_starts(&fCtx, 0); // 2nd argument selects 0=SHA-256 vs 1=SHA-224
1160
1161 return SUCCESS;
1162 }
virtual int wr_open(LOG_CHN *log_chn, int run_number)=0
void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
SHA-256 context setup.
Definition sha256.cxx:102
Here is the call graph for this function:

◆ wr_write()

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

Implements WriterInterface.

Definition at line 1164 of file mlogger.cxx.

1165 {
1166 if (fTrace)
1167 printf("WriterSHA256: write path [%s], size %d\n", log_chn->path.c_str(), size);
1168
1169 mbedtls_sha256_update(&fCtx, (const unsigned char*)data, size);
1170
1171 int status = fWr->wr_write(log_chn, data, size);
1172
1173 fBytesIn += size;
1175
1176 if (status != SUCCESS) {
1177 return status;
1178 }
1179
1180 return SUCCESS;
1181 }
virtual int wr_write(LOG_CHN *log_chn, const void *data, const int size)=0
void * data
Definition mana.cxx:268
void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
SHA-256 process buffer.
Definition sha256.cxx:240
Here is the call graph for this function:

Member Data Documentation

◆ fCtx

mbedtls_sha256_context WriterSHA256::fCtx
private

Definition at line 1249 of file mlogger.cxx.

◆ fLevel

int WriterSHA256::fLevel
private

Definition at line 1247 of file mlogger.cxx.

◆ fWr

WriterInterface* WriterSHA256::fWr
private

Definition at line 1248 of file mlogger.cxx.


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