forked from rarimo/passport-identity-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rarimo/fix/truncate
Refactor TruncateDg1Hash
- Loading branch information
Showing
7 changed files
with
114 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package utils | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTruncateDg1Hash(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputHash []byte | ||
expected [32]byte | ||
}{ | ||
{ | ||
name: "16-byte hash", | ||
inputHash: bytes.Repeat([]byte{0xDD}, 16), // Example: 16 bytes of 0xDD | ||
expected: func() [32]byte { | ||
var result [32]byte | ||
copy(result[32-16:], bytes.Repeat([]byte{0xDD}, 32)) | ||
return result | ||
}(), | ||
}, | ||
{ | ||
name: "20-byte hash", | ||
inputHash: bytes.Repeat([]byte{0xAA}, 20), // Example: 20 bytes of 0xAA | ||
expected: func() [32]byte { | ||
var result [32]byte | ||
copy(result[32-20:], bytes.Repeat([]byte{0xAA}, 32)) | ||
return result | ||
}(), | ||
}, | ||
{ | ||
name: "32-byte hash", | ||
inputHash: bytes.Repeat([]byte{0xBB}, 32), // Example: 32 bytes of 0xBB | ||
expected: func() [32]byte { | ||
var result [32]byte | ||
copy(result[1:], bytes.Repeat([]byte{0xBB}, 32)) | ||
return result | ||
}(), | ||
}, | ||
{ | ||
name: "48-byte hash", | ||
inputHash: bytes.Repeat([]byte{0xBB}, 48), // Example: 48 bytes of 0xBB | ||
expected: func() [32]byte { | ||
var result [32]byte | ||
copy(result[1:], bytes.Repeat([]byte{0xBB}, 32)) | ||
return result | ||
}(), | ||
}, | ||
{ | ||
name: "64-byte hash", | ||
inputHash: bytes.Repeat([]byte{0xCC}, 64), // Example: 64 bytes of 0xCC | ||
expected: func() [32]byte { | ||
var result [32]byte | ||
copy(result[1:], bytes.Repeat([]byte{0xCC}, 32)) | ||
return result | ||
}(), | ||
}, | ||
{ | ||
name: "128-byte hash", | ||
inputHash: bytes.Repeat([]byte{0xCC}, 128), // Example: 128 bytes of 0xCC (I don't know if this even possible, but just in case) | ||
expected: func() [32]byte { | ||
var result [32]byte | ||
copy(result[1:], bytes.Repeat([]byte{0xCC}, 32)) | ||
return result | ||
}(), | ||
}, | ||
|
||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := TruncateDg1Hash(tt.inputHash) | ||
t.Logf("Input Hash: \t\t0x%X", tt.inputHash) | ||
t.Logf("Truncated Result:\t0x%X", result) | ||
assert.Equal(t, tt.expected, result, "Truncated hash should match expected value") | ||
}) | ||
} | ||
} |