/*
* DKID class constructor, does default initialization.
*/
-DKID::DKID()
-{
- bmemzero(Digest, DKIDDIGESTSIZE + 1);
- ShortD = DKIDInvalid;
- shortonly = false;
-};
-
-/*
- * DKID class constructor, does parm initialization.
- */
-DKID::DKID(const char* data)
-{
- init(data);
-};
-
-/*
- * DKID class constructor, does parm initialization.
- */
-DKID::DKID(POOL_MEM& data)
+DKID::DKID() :
+ ShortD(DKIDInvalid),
+#if __cplusplus > 201103L
+ Digest{0},
+ DigestShort{0},
+#endif
+ shortonly(false)
{
- init(data.c_str());
+#if ! __cplusplus > 201103L
+ bmemzero(Digest, DKIDDIGESTSIZE_Len);
+ bmemzero(DigestShort, DKIDDIGESTShortSIZE_Len);
+#endif
};
/*
*/
void DKID::init(const char* data)
{
- int len;
- int a;
- unsigned char c;
- bool valid = true;
char *dig = (char*)data;
if (dig != NULL){
if (strstr(dig, "sha256:") == dig){
dig += 7;
}
- len = strlen(dig);
+ int len = strlen(dig);
/* check for invalid input data */
- for (a = 0; a < (len > DKIDDIGESTShortSIZE ? DKIDDIGESTShortSIZE : len); a++){
+ bool valid = true;
+ for (int a = 0; a < (len > DKIDDIGESTShortSIZE ? DKIDDIGESTShortSIZE : len); a++){
// we are checking for ASCII codes, a subset of UTF-8 for short digest only
- c = (unsigned char)dig[a];
+ unsigned char c = (unsigned char)dig[a];
if (c > 'f' || (c > '9' && c < 'A') || (c > 'F' && c < 'a')){
valid = false;
break;
return report();
};
-#endif /* TEST_PROGRAM */
\ No newline at end of file
+#endif /* TEST_PROGRAM */
#include "bacula.h"
-#define DKIDDIGESTSIZE 64 // the size of string array for hex chars, without trailing nul
-#define DKIDDIGESTShortSIZE 12 // the number of hex characters in short digest, without trailing nul
-#define DKIDInvalid -256 // the non-trivial negative value :)
+#define DKIDDIGESTSIZE 64 // the size of string array for hex chars, without trailing nul
+#define DKIDDIGESTSIZE_Len (DKIDDIGESTSIZE + 1) // the size of string array for hex chars, with trailing nul
+#define DKIDDIGESTShortSIZE 12 // the number of hex characters in short digest, without trailing nul
+#define DKIDDIGESTShortSIZE_Len (DKIDDIGESTShortSIZE + 1) // the number of hex characters in short digest, without trailing nul
+#define DKIDInvalid -256 // the non-trivial negative value :)
/*
* This is a simple storage class to handle Docker Container IDs
*/
-class DKID: public SMARTALLOC {
- public:
- DKID();
- DKID(const char *data);
- DKID(POOL_MEM &data);
- ~DKID() {};
+class DKID: public SMARTALLOC
+{
+public:
+ DKID();
+ DKID(const char *data) { init(data); }
+ DKID(POOL_MEM &data) { init(data.c_str()); }
+#if __cplusplus > 201103L
+ ~DKID() = default;
+#else
+ ~DKID() {};
+#endif
- inline int64_t id() { return ShortD; };
- inline char *digest() { return Digest; };
- inline char *digest_short() { return DigestShort; };
- inline operator int64_t () { return ShortD; };
- inline operator char* () { return Digest; };
- DKID& operator= (char *data);
- DKID& operator= (DKID &other);
- DKID& operator= (POOL_MEM &data);
- bool operator== (DKID &other);
- bool operator!= (DKID &other);
+ inline int64_t id() { return ShortD; };
+ inline char *digest() { return Digest; };
+ inline char *digest_short() { return DigestShort; };
+ inline operator int64_t () { return ShortD; };
+ inline operator char* () { return Digest; };
+ DKID& operator= (char *data);
+ DKID& operator= (DKID &other);
+ DKID& operator= (POOL_MEM &data);
+ bool operator== (DKID &other);
+ bool operator!= (DKID &other);
#ifdef TEST_PROGRAM
- void dump();
+ void dump();
#endif
- private:
- char Digest[DKIDDIGESTSIZE + 1];
- char DigestShort[DKIDDIGESTShortSIZE + 1];
+private:
int64_t ShortD; // default short digest on Docker is 48bits/6bytes/12hex chars
// https://github.com/docker/cli/blob/master/vendor/github.com/docker/docker/pkg/stringid/stringid.go
+ char Digest[DKIDDIGESTSIZE_Len];
+ char DigestShort[DKIDDIGESTShortSIZE_Len];
bool shortonly;
void init(const char* d);