Skip to content

Commit 93c8ed3

Browse files
committed
Add tag2 for gnu/bsd tag names
1 parent e0fe4aa commit 93c8ed3

File tree

3 files changed

+65
-33
lines changed

3 files changed

+65
-33
lines changed

Diff for: README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ $ ddh --md5 LICENSE
6969
1d267ceb3a8d8f75f1be3011ee4cbf53 LICENSE
7070
```
7171

72+
To select OpenSSL tags for the output, use `--tag`.
73+
74+
To select SRI for the output, use `--sri`.
75+
7276
## Check list using hash
7377

7478
```text
@@ -78,7 +82,9 @@ file2: FAILED
7882
2 total: 1 mismatch, 0 not read
7983
```
8084

81-
To select the BSD style tags, use `--tag`.
85+
To select the tag digest style, use `--tag`.
86+
87+
Both OpenSSL and GNU/BSD tags are supported.
8288

8389
## Check files against a hash digest
8490

Diff for: src/ddh.d

+45-24
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ enum InvalidHash = cast(HashType)-1;
5555
struct HashInfo
5656
{
5757
HashType type;
58-
string fullName, alias_, tagName;
58+
string fullName, alias_, tag, tag2;
5959
}
6060

6161
immutable
@@ -93,28 +93,49 @@ immutable
9393
// For some reason, NetBSD seems to be using other names such as RMD160,
9494
// SHA512, etc. under OpenSSL. Is this a GNU/BSD thing?
9595
immutable HashInfo[HashCount] hashInfo = [
96-
// HashType Full Alias, Tag
97-
{ HashType.CRC32, "CRC-32", crc32, "CRC32", },
98-
{ HashType.CRC64ISO, "CRC-64-ISO", crc64iso, "CRC64ISO", },
99-
{ HashType.CRC64ECMA, "CRC-64-ECMA", crc64ecma, "CRC64ECMA", },
100-
{ HashType.MurmurHash3_32, "MurmurHash3-32", murmur3a, "MURMURHASH3-32", },
101-
{ HashType.MurmurHash3_128_32, "MurmurHash3-128/32", murmur3c, "MURMURHASH3-128-32", },
102-
{ HashType.MurmurHash3_128_64, "MurmurHash3-128/64", murmur3f, "MURMURHASH3-128-64", },
103-
{ HashType.MD5, "MD5-128", md5, "MD5", },
104-
{ HashType.RIPEMD160, "RIPEMD-160", ripemd160, "RIPEMD160", },
105-
{ HashType.SHA1, "SHA-1-160", sha1, "SHA1", },
106-
{ HashType.SHA224, "SHA-2-224", sha224, "SHA2-224", },
107-
{ HashType.SHA256, "SHA-2-256", sha256, "SHA2-256", },
108-
{ HashType.SHA384, "SHA-2-384", sha384, "SHA2-384", },
109-
{ HashType.SHA512, "SHA-2-512", sha512, "SHA2-512", },
110-
{ HashType.SHA3_224, "SHA-3-224", sha3_224, "SHA3-224", },
111-
{ HashType.SHA3_256, "SHA-3-256", sha3_256, "SHA3-256", },
112-
{ HashType.SHA3_384, "SHA-3-384", sha3_384, "SHA3-384", },
113-
{ HashType.SHA3_512, "SHA-3-512", sha3_512, "SHA3-512", },
114-
{ HashType.SHAKE128, "SHAKE-128", shake128, "SHAKE-128", },
115-
{ HashType.SHAKE256, "SHAKE-256", shake256, "SHAKE-256", },
116-
{ HashType.BLAKE2b512, "BLAKE2b-512", blake2b512, "BLAKE2B-512", },
117-
{ HashType.BLAKE2s256, "BLAKE2s-256", blake2s256, "BLAKE2S-256", },
96+
// HashType, Full, Alias, Tag (openssl), Tag2 (gnu)
97+
{ HashType.CRC32,
98+
"CRC-32", crc32, "CRC32", },
99+
{ HashType.CRC64ISO,
100+
"CRC-64-ISO", crc64iso, "CRC64ISO", },
101+
{ HashType.CRC64ECMA,
102+
"CRC-64-ECMA", crc64ecma, "CRC64ECMA", },
103+
{ HashType.MurmurHash3_32,
104+
"MurmurHash3-32", murmur3a, "MURMURHASH3-32", },
105+
{ HashType.MurmurHash3_128_32,
106+
"MurmurHash3-128/32", murmur3c, "MURMURHASH3-128-32", },
107+
{ HashType.MurmurHash3_128_64,
108+
"MurmurHash3-128/64", murmur3f, "MURMURHASH3-128-64", },
109+
{ HashType.MD5,
110+
"MD5-128", md5, "MD5", },
111+
{ HashType.RIPEMD160,
112+
"RIPEMD-160", ripemd160, "RIPEMD160", "RMD160" },
113+
{ HashType.SHA1,
114+
"SHA-1-160", sha1, "SHA1", },
115+
{ HashType.SHA224,
116+
"SHA-2-224", sha224, "SHA2-224", "SHA224" },
117+
{ HashType.SHA256,
118+
"SHA-2-256", sha256, "SHA2-256", "SHA256" },
119+
{ HashType.SHA384,
120+
"SHA-2-384", sha384, "SHA2-384", "SHA384" },
121+
{ HashType.SHA512,
122+
"SHA-2-512", sha512, "SHA2-512", "SHA512" },
123+
{ HashType.SHA3_224,
124+
"SHA-3-224", sha3_224, "SHA3-224", },
125+
{ HashType.SHA3_256,
126+
"SHA-3-256", sha3_256, "SHA3-256", },
127+
{ HashType.SHA3_384,
128+
"SHA-3-384", sha3_384, "SHA3-384", },
129+
{ HashType.SHA3_512,
130+
"SHA-3-512", sha3_512, "SHA3-512", },
131+
{ HashType.SHAKE128,
132+
"SHAKE-128", shake128, "SHAKE-128", },
133+
{ HashType.SHAKE256,
134+
"SHAKE-256", shake256, "SHAKE-256", },
135+
{ HashType.BLAKE2b512,
136+
"BLAKE2b-512", blake2b512, "BLAKE2B-512", },
137+
{ HashType.BLAKE2s256,
138+
"BLAKE2s-256", blake2s256, "BLAKE2S-256", },
118139
];
119140

120141
struct Ddh
@@ -225,7 +246,7 @@ struct Ddh
225246

226247
string tagName()
227248
{
228-
return info.tagName;
249+
return info.tag;
229250
}
230251
}
231252

Diff for: src/main.d

+13-8
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ int processList(const(char)[] listPath)
576576

577577
if (settings.autocheck)
578578
{
579-
settings.type = guessHashExt(listPath);
579+
settings.type = guessHash(listPath);
580580
if (settings.type == InvalidHash)
581581
logError(5, "Could not determine hash type");
582582
}
@@ -625,7 +625,12 @@ int processList(const(char)[] listPath)
625625
lastType = type;
626626
foreach (HashInfo info; hashInfo)
627627
{
628-
if (type == info.tagName)
628+
if (type == info.tag)
629+
{
630+
settings.hasher.initiate(info.type);
631+
break TAGTYPE;
632+
}
633+
if (type == info.tag2)
629634
{
630635
settings.hasher.initiate(info.type);
631636
break TAGTYPE;
@@ -731,9 +736,9 @@ int processCompare(string[] entries)
731736
return 0;
732737
}
733738

734-
void printMeta(string baseName, string name, string tagName)
739+
void printMeta(string baseName, string name, string tag, string tag2)
735740
{
736-
writefln("%-18s %-18s %s", baseName, name, tagName);
741+
writefln("%-18s %-18s %-18s %s", baseName, name, tag, tag2);
737742
}
738743

739744
// special settings that getopts cannot simply set directly
@@ -811,7 +816,7 @@ int cliAutoCheck(string[] entries)
811816
{
812817
version (Trace) trace("entry=%s", entry);
813818

814-
settings.type = guessHashExt(entry);
819+
settings.type = guessHash(entry);
815820
if (settings.type == InvalidHash)
816821
logError(7, "Could not determine hash type for: %s", entry);
817822

@@ -829,10 +834,10 @@ int cliAutoCheck(string[] entries)
829834
void cliHashes()
830835
{
831836
static immutable string sep = "-----------";
832-
printMeta("Alias", "Name", "Tag");
833-
printMeta(sep, sep, sep);
837+
printMeta("Alias", "Name", "Tag", "Tag2");
838+
printMeta(sep, sep, sep, sep);
834839
foreach (info; hashInfo)
835-
printMeta(info.alias_, info.fullName, info.tagName);
840+
printMeta(info.alias_, info.fullName, info.tag, info.tag2);
836841
exit(0);
837842
}
838843

0 commit comments

Comments
 (0)