@@ -62,3 +62,120 @@ func TestDigest_SHA256(t *testing.T) {
6262
6363 assert .Equal (t , `sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:` , hdr .Get (ContentDigestHeader ))
6464}
65+
66+ func TestVerify_SHA256 (t * testing.T ) {
67+ body := []byte ("{\" hello\" : \" world\" }\n " )
68+
69+ d := NewDigestor (
70+ WithDigestAlgorithms (DigestAlgorithmSha256 ),
71+ )
72+
73+ hdr , err := d .Digest (body )
74+ assert .NoError (t , err )
75+
76+ err = d .Verify (body , hdr )
77+ assert .NoError (t , err )
78+ }
79+
80+ func TestVerify_SHA512 (t * testing.T ) {
81+ body := []byte ("{\" hello\" : \" world\" }\n " )
82+
83+ d := NewDigestor (
84+ WithDigestAlgorithms (DigestAlgorithmSha512 ),
85+ )
86+
87+ hdr , err := d .Digest (body )
88+ assert .NoError (t , err )
89+
90+ err = d .Verify (body , hdr )
91+ assert .NoError (t , err )
92+ }
93+
94+ func TestDigest_SHA256_Verify_SHA256_SHA512 (t * testing.T ) {
95+ body := []byte ("{\" hello\" : \" world\" }\n " )
96+
97+ d := NewDigestor (
98+ WithDigestAlgorithms (DigestAlgorithmSha256 ),
99+ )
100+
101+ hdr , err := d .Digest (body )
102+ assert .NoError (t , err )
103+
104+ err = d .Verify (body , hdr )
105+ assert .NoError (t , err )
106+
107+ d = NewDigestor (
108+ WithDigestAlgorithms (DigestAlgorithmSha256 ),
109+ WithDigestAlgorithms (DigestAlgorithmSha512 ),
110+ )
111+
112+ err = d .Verify (body , hdr )
113+ assert .NoError (t , err )
114+ }
115+
116+ func TestDigest_SHA256_SHA512_Verify_SHA256_SHA512 (t * testing.T ) {
117+ body := []byte ("{\" hello\" : \" world\" }\n " )
118+
119+ d := NewDigestor (
120+ WithDigestAlgorithms (DigestAlgorithmSha256 ),
121+ WithDigestAlgorithms (DigestAlgorithmSha512 ),
122+ )
123+
124+ hdr , err := d .Digest (body )
125+ assert .NoError (t , err )
126+
127+ err = d .Verify (body , hdr )
128+ assert .NoError (t , err )
129+
130+ d = NewDigestor (
131+ WithDigestAlgorithms (DigestAlgorithmSha256 ),
132+ WithDigestAlgorithms (DigestAlgorithmSha512 ),
133+ )
134+
135+ err = d .Verify (body , hdr )
136+ assert .NoError (t , err )
137+ }
138+
139+ func TestDigest_SHA256_SHA512_Verify_SHA256 (t * testing.T ) {
140+ body := []byte ("{\" hello\" : \" world\" }\n " )
141+
142+ d := NewDigestor (
143+ WithDigestAlgorithms (DigestAlgorithmSha256 ),
144+ WithDigestAlgorithms (DigestAlgorithmSha512 ),
145+ )
146+
147+ hdr , err := d .Digest (body )
148+ assert .NoError (t , err )
149+
150+ err = d .Verify (body , hdr )
151+ assert .NoError (t , err )
152+
153+ d = NewDigestor (
154+ WithDigestAlgorithms (DigestAlgorithmSha256 ),
155+ )
156+
157+ err = d .Verify (body , hdr )
158+ assert .NoError (t , err )
159+ }
160+
161+ func TestDigest_SHA256_SHA512_Verify_SHA512 (t * testing.T ) {
162+ body := []byte ("{\" hello\" : \" world\" }\n " )
163+
164+ d := NewDigestor (
165+ WithDigestAlgorithms (DigestAlgorithmSha256 ),
166+ WithDigestAlgorithms (DigestAlgorithmSha512 ),
167+ )
168+
169+ hdr , err := d .Digest (body )
170+ assert .NoError (t , err )
171+
172+ err = d .Verify (body , hdr )
173+ assert .NoError (t , err )
174+
175+ d = NewDigestor (
176+ WithDigestAlgorithms (DigestAlgorithmSha512 ),
177+ )
178+
179+ err = d .Verify (body , hdr )
180+ assert .NoError (t , err )
181+ }
0 commit comments