|
1 | 1 | package prio3 |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "github.com/cloudflare/circl/internal/conv" |
5 | 6 | "github.com/cloudflare/circl/vdaf/prio3/arith" |
6 | 7 | "golang.org/x/crypto/cryptobyte" |
@@ -360,6 +361,32 @@ func (s *OutShare[V, E]) Unmarshal(str *cryptobyte.String) bool { |
360 | 361 | return s.share.Unmarshal(str) |
361 | 362 | } |
362 | 363 |
|
| 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 | + |
363 | 390 | // AggShare represents the following structure. |
364 | 391 | // |
365 | 392 | // struct { |
|
0 commit comments