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

Constructor & Destructor Documentation

◆ WriterSHA256()

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

Definition at line 1145 of file mlogger.cxx.

1146 {
1147 if (fTrace)
1148 printf("WriterSHA256: path [%s], level %d\n", log_chn->path.c_str(), level);
1149
1150 assert(wr != NULL);
1151
1152 fLevel = level;
1153 fWr = wr;
1154
1156 }
mbedtls_sha256_context fCtx
Definition mlogger.cxx:1275
WriterInterface * fWr
Definition mlogger.cxx:1274
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
Initialize SHA-256 context.
Definition sha256.cxx:80
Here is the call graph for this function:

◆ ~WriterSHA256()

WriterSHA256::~WriterSHA256 ( )
inline

Definition at line 1158 of file mlogger.cxx.

1159 {
1160 if (fTrace)
1161 printf("WriterSHA256: destructor\n");
1162 DELETE(fWr);
1163
1165 }
#define DELETE(ptr)
Definition mlogger.cxx:368
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 1209 of file mlogger.cxx.

1210 {
1211 char s[3];
1212 sprintf(s, "%02x", c);
1213 return s;
1214 }
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 WriterSHA256::toString ( const unsigned char  sha256sum[32])
inline

Definition at line 1216 of file mlogger.cxx.

1217 {
1218 std::string s;
1219 for (int i=0; i<32; i++)
1220 s += toHex(sha256sum[i]);
1221 return s;
1222 }
std::string toHex(unsigned char c)
Definition mlogger.cxx:1209
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 1224 of file mlogger.cxx.

1225 {
1226 std::string x = xpathname(log_chn->path.c_str(), fLevel);
1227 std::string f = x + ".sha256";
1228
1229 if (fTrace)
1230 printf("WriterSHA256: close path [%s], level %d, file [%s]\n", log_chn->path.c_str(), fLevel, f.c_str());
1231
1232 log_chn->handle = 0;
1233
1234 unsigned char sha256sum[32];
1236
1237 //std::string s = toString(sha256sum);
1238 //printf("sha256 %s\n", s.c_str());
1239
1240 cm_msg(MLOG, "SHA256", "File \'%s\' SHA-256 checksum: %s, %.0f bytes", x.c_str(), toString(sha256sum).c_str(), fBytesIn);
1241
1242 FILE *fp = fopen_wx(f.c_str());
1243 if (!fp) {
1244 cm_msg(MERROR, "WriterSHA256::wr_close", "Cannot write SHA-256 checksum to file \'%s\', fopen() errno %d (%s)", f.c_str(), errno, strerror(errno));
1245 } else {
1246 fprintf(fp, "%s %.0f %s\n", toString(sha256sum).c_str(), fBytesIn, x.c_str());
1247 fclose(fp);
1248 }
1249
1250 /* close downstream writer */
1251
1253
1254 fBytesIn += 0;
1256
1257 if (status != SUCCESS) {
1258 return status;
1259 }
1260
1261 return SUCCESS;
1262 }
virtual int wr_close(LOG_CHN *log_chn, int run_number)=0
std::string toString(const unsigned char sha256sum[32])
Definition mlogger.cxx:1216
#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_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
SHA-256 final digest.
Definition sha256.cxx:289
Here is the call graph for this function:

◆ wr_get_chain()

std::string WriterSHA256::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 1268 of file mlogger.cxx.

1268 {
1269 return "SHA256 | " + fWr->wr_get_chain();
1270 }
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 1264 of file mlogger.cxx.

1264 {
1265 return fWr->wr_get_file_ext();
1266 }
virtual std::string wr_get_file_ext()
Definition mlogger.cxx:414
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 1167 of file mlogger.cxx.

1168 {
1169 int status;
1170
1171 if (fTrace)
1172 printf("WriterSHA256: open path [%s], level %d\n", log_chn->path.c_str(), fLevel);
1173
1175
1176 fBytesIn += 0;
1178
1179 if (status != SUCCESS) {
1180 return status;
1181 }
1182
1183 log_chn->handle = 9999;
1184
1185 mbedtls_sha256_starts(&fCtx, 0); // 2nd argument selects 0=SHA-256 vs 1=SHA-224
1186
1187 return SUCCESS;
1188 }
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 1190 of file mlogger.cxx.

1191 {
1192 if (fTrace)
1193 printf("WriterSHA256: write path [%s], size %d\n", log_chn->path.c_str(), size);
1194
1195 mbedtls_sha256_update(&fCtx, (const unsigned char*)data, size);
1196
1197 int status = fWr->wr_write(log_chn, data, size);
1198
1199 fBytesIn += size;
1201
1202 if (status != SUCCESS) {
1203 return status;
1204 }
1205
1206 return SUCCESS;
1207 }
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 1275 of file mlogger.cxx.

◆ fLevel

int WriterSHA256::fLevel
private

Definition at line 1273 of file mlogger.cxx.

◆ fWr

WriterInterface* WriterSHA256::fWr
private

Definition at line 1274 of file mlogger.cxx.


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