cloneHash uses the encoding.BinaryMarshaler and encoding.BinaryUnmarshaler interfaces implemented by standard library hashes to clone the state of in to a new instance of h. It returns nil if the operation fails.
(in hash.Hash, h crypto.Hash)
| 566 | // interfaces implemented by standard library hashes to clone the state of in |
| 567 | // to a new instance of h. It returns nil if the operation fails. |
| 568 | func cloneHash(in hash.Hash, h crypto.Hash) hash.Hash { |
| 569 | // Recreate the interface to avoid importing encoding. |
| 570 | type binaryMarshaler interface { |
| 571 | MarshalBinary() (data []byte, err error) |
| 572 | UnmarshalBinary(data []byte) error |
| 573 | } |
| 574 | marshaler, ok := in.(binaryMarshaler) |
| 575 | if !ok { |
| 576 | return nil |
| 577 | } |
| 578 | state, err := marshaler.MarshalBinary() |
| 579 | if err != nil { |
| 580 | return nil |
| 581 | } |
| 582 | out := h.New() |
| 583 | unmarshaler, ok := out.(binaryMarshaler) |
| 584 | if !ok { |
| 585 | return nil |
| 586 | } |
| 587 | if err := unmarshaler.UnmarshalBinary(state); err != nil { |
| 588 | return nil |
| 589 | } |
| 590 | return out |
| 591 | } |
| 592 | |
| 593 | func (hs *serverHandshakeStateTLS13) pickCertificate() error { |
| 594 | c := hs.c |
no test coverage detected
searching dependent graphs…