ceremonyclient/nekryptology/pkg/tecdsa/dkls/v0/conn.go
2023-07-05 00:32:28 -05:00

34 lines
747 B
Go

//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
package v0
import "io"
type pipeWrapper struct {
r *io.PipeReader
w *io.PipeWriter
exchanged int // basically we only use this during testing, to track bytes exchanged
}
func (wrapper *pipeWrapper) Write(p []byte) (n int, err error) {
n, err = wrapper.w.Write(p)
wrapper.exchanged += n
return
}
func (wrapper *pipeWrapper) Read(p []byte) (n int, err error) {
n, err = wrapper.r.Read(p)
wrapper.exchanged += n
return
}
func NewPipeWrappers() (*pipeWrapper, *pipeWrapper) {
leftOut, leftIn := io.Pipe()
rightOut, rightIn := io.Pipe()
return &pipeWrapper{r: leftOut, w: rightIn}, &pipeWrapper{r: rightOut, w: leftIn}
}