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)
| 323 | // interfaces implemented by standard library hashes to clone the state of in |
| 324 | // to a new instance of h. It returns nil if the operation fails. |
| 325 | func cloneHash(in hash.Hash, h crypto.Hash) hash.Hash { |
| 326 | // Recreate the interface to avoid importing encoding. |
| 327 | type binaryMarshaler interface { |
| 328 | MarshalBinary() (data []byte, err error) |
| 329 | UnmarshalBinary(data []byte) error |
| 330 | } |
| 331 | marshaler, ok := in.(binaryMarshaler) |
| 332 | if !ok { |
| 333 | return nil |
| 334 | } |
| 335 | state, err := marshaler.MarshalBinary() |
| 336 | if err != nil { |
| 337 | return nil |
| 338 | } |
| 339 | out := h.New() |
| 340 | unmarshaler, ok := out.(binaryMarshaler) |
| 341 | if !ok { |
| 342 | return nil |
| 343 | } |
| 344 | if err := unmarshaler.UnmarshalBinary(state); err != nil { |
| 345 | return nil |
| 346 | } |
| 347 | return out |
| 348 | } |
| 349 | |
| 350 | func (hs *serverHandshakeStateTLS13) pickCertificate() error { |
| 351 | c := hs.c |
no test coverage detected
searching dependent graphs…