encoding.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package kyber
  2. import (
  3. "encoding"
  4. "io"
  5. )
  6. /*
  7. Marshaling is a basic interface representing fixed-length (or known-length)
  8. cryptographic objects or structures having a built-in binary encoding.
  9. Implementors must ensure that calls to these methods do not modify
  10. the underlying object so that other users of the object can access
  11. it concurrently.
  12. */
  13. type Marshaling interface {
  14. encoding.BinaryMarshaler
  15. encoding.BinaryUnmarshaler
  16. // String returns the human readable string representation of the object.
  17. String() string
  18. // Encoded length of this object in bytes.
  19. MarshalSize() int
  20. // Encode the contents of this object and write it to an io.Writer.
  21. MarshalTo(w io.Writer) (int, error)
  22. // Decode the content of this object by reading from an io.Reader.
  23. // If r is an XOF, it uses r to pick a valid object pseudo-randomly,
  24. // which may entail reading more than Len bytes due to retries.
  25. UnmarshalFrom(r io.Reader) (int, error)
  26. }
  27. // Encoding represents an abstract interface to an encoding/decoding that can be
  28. // used to marshal/unmarshal objects to and from streams. Different Encodings
  29. // will have different constraints, of course. Two implementations are
  30. // available:
  31. //
  32. // 1. The protobuf encoding using the variable length Google Protobuf encoding
  33. // scheme. The library is available at https://go.dedis.ch/protobuf
  34. // 2. The fixbuf encoding, a fixed length binary encoding of arbitrary
  35. // structures. The library is available at https://go.dedis.ch/fixbuf.
  36. type Encoding interface {
  37. // Encode and write objects to an io.Writer.
  38. Write(w io.Writer, objs ...interface{}) error
  39. // Read and decode objects from an io.Reader.
  40. Read(r io.Reader, objs ...interface{}) error
  41. }