Skip to content

Commit

Permalink
refactoring: added match field, removed regexp field
Browse files Browse the repository at this point in the history
started work to close #1

additionally added support for GRUB 2 hashes and added a test for it.
  • Loading branch information
CPunch committed Oct 4, 2023
1 parent 2870e12 commit ce4a916
Show file tree
Hide file tree
Showing 3 changed files with 516 additions and 153 deletions.
2 changes: 1 addition & 1 deletion detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func Detect(hash string) []HashInfo {
var hashes []HashInfo

for _, proto := range prototypes {
if proto.regexp.MatchString(hash) {
if proto.match(hash) {
hashes = append(hashes, proto.mode...)
}
}
Expand Down
6 changes: 6 additions & 0 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ func TestSha256(t *testing.T) {
t.Errorf("Expected SHA-256, got %v", hashes)
}
}

func TestGRUB2(t *testing.T) {
if hashes := Detect("grub.pbkdf2.sha512.10000.7d391ef48645f626b427b1fae06a7219b5b54f4f02b2621f86b5e36e83ae492bd1db60871e45bc07925cecb46ff8ba3db31c723c0c6acbd4f06f60c5b246ecbf.26d59c52b50df90d043f070bd9cbcd92a74424da42b3666fdeb08f1a54b8f1d2f4f56cf436f9382419c26798dc2c209a86003982b1e5a9fcef905f4dfaa4c524"); !checkIncludedHash(hashes, "GRUB 2") {
t.Errorf("Expected GRUB2, got %v", hashes)
}
}
Loading

0 comments on commit ce4a916

Please sign in to comment.