MCPcopy Create free account
hub / github.com/XTLS/Go / cloneHash

Function cloneHash

handshake_server_tls13.go:325–348  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
325func 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
350func (hs *serverHandshakeStateTLS13) pickCertificate() error {
351 c := hs.c

Callers 1

checkForResumptionMethod · 0.85

Calls 2

MarshalBinaryMethod · 0.80
UnmarshalBinaryMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…