Documentation ¶
Overview ¶
Package headers contains structure and related methods for representing Crypt4GH header packets.
Index ¶
- Constants
- func EncryptedSegmentSize(header []byte, readerPrivateKey [chacha20poly1305.KeySize]byte) (int, error)
- func ReEncryptHeader(oldHeader []byte, readerPrivateKey [chacha20poly1305.KeySize]byte, ...) (newBinaryHeader []byte, err error)
- func ReadHeader(reader io.Reader) (header []byte, err error)
- type DataEditListHeaderPacket
- type DataEncryptionMethod
- type DataEncryptionParametersHeaderPacket
- type EncryptedHeaderPacket
- type Header
- type HeaderEncryptionMethod
- type HeaderPacket
- type HeaderPacketType
- type HeaderReaderError
- type PacketType
Constants ¶
const ( // MagicNumber is standard beginning of Crypt4GH header. MagicNumber string = "crypt4gh" // Version stands for current supported version. Version uint32 = 1 // UnencryptedDataSegmentSize is the size of chunk of raw data. UnencryptedDataSegmentSize int = 65536 // MaxAllowedHeaderPackets is the highest number of header packets // we allow. MaxAllowedHeaderPackets uint32 = 65536 // MaxAllowedHeaderPackets is the highest length of a single header packet // we allow. MaxAllowedHeaderPacketLength uint32 = 16 * 1024 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func EncryptedSegmentSize ¶ added in v1.10.0
func EncryptedSegmentSize(header []byte, readerPrivateKey [chacha20poly1305.KeySize]byte) (int, error)
EncryptedSegmentSize returns the size of an encrypted segment for a given header and reader private key.
func ReEncryptHeader ¶ added in v1.6.0
func ReEncryptHeader(oldHeader []byte, readerPrivateKey [chacha20poly1305.KeySize]byte, readerPublicKeyList [][chacha20poly1305.KeySize]byte, additionalEncryptedHeaderPackets ...EncryptedHeaderPacket) (newBinaryHeader []byte, err error)
ReEncryptHeader takes an old header, decrypts it and using a list of receivers public keys re-encrypts the header for those keys while keeping the dataEditList packets. Optionally adds additional headers, replacing any previous headers of the same type
Types ¶
type DataEditListHeaderPacket ¶
type DataEditListHeaderPacket struct { PacketType NumberLengths uint32 Lengths []uint64 }
DataEditListHeaderPacket structure represents Crypt4GH data edit list header packet.
func NewDataEditListHeaderPacket ¶
func NewDataEditListHeaderPacket(reader io.Reader) (*DataEditListHeaderPacket, error)
NewDataEditListHeaderPacket method constructs DataEditListHeaderPacket from io.Reader.
func (DataEditListHeaderPacket) MarshalBinary ¶
func (delhp DataEditListHeaderPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements method MarshalBinary.BinaryMarshaler.
type DataEncryptionMethod ¶
type DataEncryptionMethod uint32
DataEncryptionMethod is the enum listing supported methods of encryption for data segments.
const ( // ChaCha20IETFPoly1305 is header encryption method for ChaCha20-IETF-Poly1305. ChaCha20IETFPoly1305 DataEncryptionMethod = iota )
type DataEncryptionParametersHeaderPacket ¶
type DataEncryptionParametersHeaderPacket struct { EncryptedSegmentSize int PacketType DataEncryptionMethod DataEncryptionMethod DataKey [chacha20poly1305.KeySize]byte }
DataEncryptionParametersHeaderPacket structure represents Crypt4GH data encryption parameters header packet.
func NewDataEncryptionParametersHeaderPacket ¶
func NewDataEncryptionParametersHeaderPacket(reader io.Reader) (*DataEncryptionParametersHeaderPacket, error)
NewDataEncryptionParametersHeaderPacket method constructs DataEncryptionParametersHeaderPacket from io.Reader.
func (DataEncryptionParametersHeaderPacket) MarshalBinary ¶
func (dephp DataEncryptionParametersHeaderPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements method MarshalBinary.BinaryMarshaler.
type EncryptedHeaderPacket ¶
type EncryptedHeaderPacket interface { // GetPacketType method returns packet type of the header packet. GetPacketType() HeaderPacketType // MarshalBinary implements method MarshalBinary.BinaryMarshaler. MarshalBinary() (data []byte, err error) }
EncryptedHeaderPacket interface describes possible header packets: DataEncryptionParametersHeaderPacket and DataEditListHeaderPacket.
func NewEncryptedHeaderPacket ¶
func NewEncryptedHeaderPacket(encryptedPacketPayload []byte, readerPrivateKey [chacha20poly1305.KeySize]byte) (*EncryptedHeaderPacket, error)
NewEncryptedHeaderPacket method constructs EncryptedHeaderPacket from io.Reader and supplied private key. headerEncryptionMethod HeaderEncryptionMethod was not used thus we remove it
type Header ¶
type Header struct { MagicNumber [8]byte Version uint32 HeaderPacketCount uint32 HeaderPackets []HeaderPacket }
Header structure represents Crypt4GH header.
func (Header) GetDataEditListHeaderPacket ¶
func (h Header) GetDataEditListHeaderPacket() *DataEditListHeaderPacket
GetDataEditListHeaderPacket returns packet of type DataEditListHeaderPacket. Note that only one DataEditListHeaderPacket is returned - even if there are more in the Header.
func (Header) GetDataEncryptionParameterHeaderPackets ¶
func (h Header) GetDataEncryptionParameterHeaderPackets() (*[]DataEncryptionParametersHeaderPacket, error)
GetDataEncryptionParameterHeaderPackets returns packets of type DataEncryptionParameterHeader.
func (Header) MarshalBinary ¶
MarshalBinary implements method MarshalBinary.BinaryMarshaler.
type HeaderEncryptionMethod ¶
type HeaderEncryptionMethod uint32
HeaderEncryptionMethod is the enum listing supported methods of encryption for header packets.
const ( // X25519ChaCha20IETFPoly1305 is header encryption method for X25519-ChaCha20-IETF-Poly1305. X25519ChaCha20IETFPoly1305 HeaderEncryptionMethod = iota )
type HeaderPacket ¶
type HeaderPacket struct { WriterPrivateKey [chacha20poly1305.KeySize]byte ReaderPublicKey [chacha20poly1305.KeySize]byte PacketLength uint32 HeaderEncryptionMethod HeaderEncryptionMethod Nonce *[chacha20poly1305.NonceSize]byte EncryptedHeaderPacket EncryptedHeaderPacket }
HeaderPacket structure represents Crypt4GH header packet.
func NewHeaderPacket ¶
func NewHeaderPacket(reader io.Reader, readerPrivateKey [chacha20poly1305.KeySize]byte) (*HeaderPacket, error)
NewHeaderPacket method constructs HeaderPacket from io.Reader and supplied private key.
func (*HeaderPacket) MarshalBinary ¶
func (hp *HeaderPacket) MarshalBinary() (data []byte, err error)
MarshalBinary implements method MarshalBinary.BinaryMarshaler.
type HeaderPacketType ¶
type HeaderPacketType uint32
HeaderPacketType is the enum listing possible header packet types.
const ( // DataEncryptionParameters is a packet type for data encryption parameters header packet. DataEncryptionParameters HeaderPacketType = iota // DataEditList is a packet type for data edit list header packet. DataEditList )
type HeaderReaderError ¶
type HeaderReaderError struct {
ReaderPublicKey string
}
func (*HeaderReaderError) Error ¶
func (e *HeaderReaderError) Error() string
type PacketType ¶
type PacketType struct {
PacketType HeaderPacketType
}
PacketType structure is a wrapper for HeaderPacketType.
func (PacketType) GetPacketType ¶
func (pth PacketType) GetPacketType() HeaderPacketType
GetPacketType method returns packet type of the header packet.