Skip to content

Commit 70ac16c

Browse files
committed
Add ExportRaw()/ImportRaw() to enable cross-process Prio3 share serialisation
1 parent 8859101 commit 70ac16c

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

vdaf/prio3/arith/fp64/vector.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vdaf/prio3/internal/prio3/types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package prio3
22

33
import (
4+
"errors"
45
"github.com/cloudflare/circl/internal/conv"
56
"github.com/cloudflare/circl/vdaf/prio3/arith"
67
"golang.org/x/crypto/cryptobyte"
@@ -360,6 +361,32 @@ func (s *OutShare[V, E]) Unmarshal(str *cryptobyte.String) bool {
360361
return s.share.Unmarshal(str)
361362
}
362363

364+
// ExportBytes returns the portable binary encoding of the OutShare.
365+
func (s *OutShare[V, E]) ExportBytes() ([]byte, error) {
366+
return s.MarshalBinary()
367+
}
368+
369+
// ImportBytes sets the OutShare from a portable binary encoding.
370+
func (s *OutShare[V, E]) ImportBytes(data []byte) error {
371+
return s.UnmarshalBinary(data)
372+
}
373+
374+
// ExportRaw returns the underlying vector as a byte slice.
375+
func (s *OutShare[V, E]) ExportRaw() ([]byte, error) {
376+
if b, ok := any(s.share).(interface{ ExportRaw() ([]byte, error) }); ok {
377+
return b.ExportRaw()
378+
}
379+
return nil, errors.New("ExportRaw: underlying vector does not support ExportRaw")
380+
}
381+
382+
// ImportRaw sets the underlying vector from a byte slice.
383+
func (s *OutShare[V, E]) ImportRaw(data []byte) error {
384+
if b, ok := any(&s.share).(interface{ ImportRaw([]byte) error }); ok {
385+
return b.ImportRaw(data)
386+
}
387+
return errors.New("ImportRaw: underlying vector does not support ImportRaw")
388+
}
389+
363390
// AggShare represents the following structure.
364391
//
365392
// struct {

0 commit comments

Comments
 (0)