@@ -236,6 +236,19 @@ func isHashMarshallable(md C.GO_EVP_MD_PTR) bool {
236
236
return marshallable
237
237
}
238
238
239
+ // cloneHash is an interface that defines a Clone method.
240
+ //
241
+ // hahs.CloneHash will probably be added in Go 1.25, see https://golang.org/issue/69521,
242
+ // but we need it now.
243
+ type cloneHash interface {
244
+ hash.Hash
245
+ // Clone returns a separate Hash instance with the same state as h.
246
+ Clone () hash.Hash
247
+ }
248
+
249
+ var _ hash.Hash = (* evpHash )(nil )
250
+ var _ cloneHash = (* evpHash )(nil )
251
+
239
252
// evpHash implements generic hash methods.
240
253
type evpHash struct {
241
254
alg * hashAlgorithm
@@ -349,26 +362,26 @@ func (h *evpHash) Sum(in []byte) []byte {
349
362
// Clone returns a new evpHash object that is a deep clone of itself.
350
363
// The duplicate object contains all state and data contained in the
351
364
// original object at the point of duplication.
352
- func (h * evpHash ) Clone () ( hash.Hash , error ) {
365
+ func (h * evpHash ) Clone () hash.Hash {
353
366
h2 := & evpHash {alg : h .alg }
354
367
if h .ctx != nil {
355
368
h2 .ctx = C .go_openssl_EVP_MD_CTX_new ()
356
369
if h2 .ctx == nil {
357
- return nil , newOpenSSLError ("EVP_MD_CTX_new" )
370
+ panic ( newOpenSSLError ("EVP_MD_CTX_new" ) )
358
371
}
359
372
if C .go_openssl_EVP_MD_CTX_copy_ex (h2 .ctx , h .ctx ) != 1 {
360
373
C .go_openssl_EVP_MD_CTX_free (h2 .ctx )
361
- return nil , newOpenSSLError ("EVP_MD_CTX_copy" )
374
+ panic ( newOpenSSLError ("EVP_MD_CTX_copy" ) )
362
375
}
363
376
h2 .ctx2 = C .go_openssl_EVP_MD_CTX_new ()
364
377
if h2 .ctx2 == nil {
365
378
C .go_openssl_EVP_MD_CTX_free (h2 .ctx )
366
- return nil , newOpenSSLError ("EVP_MD_CTX_new" )
379
+ panic ( newOpenSSLError ("EVP_MD_CTX_new" ) )
367
380
}
368
381
runtime .SetFinalizer (h2 , (* evpHash ).finalize )
369
382
}
370
383
runtime .KeepAlive (h )
371
- return h2 , nil
384
+ return h2
372
385
}
373
386
374
387
// hashState returns a pointer to the internal hash structure.
0 commit comments