You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DateKeys/locator/hide.go

28 lines
1.1 KiB

package locator
import (
"bytes"
"fmt"
)
// Hide appends rest to host, a file of any kind, and returns the result with
// the offset where rest starts, which is what an Address says (spec v0.11,
// §44.1). It is hiding, not steganography: whoever analyses the host sees that
// it has extra bytes, but not what they are. Only a store that keeps the file
// byte by byte keeps it: a social network or a messaging app recompress or
// strip what is left over.
func Hide(host, rest []byte) (file []byte, offset uint64) {
file = append(bytes.Clone(host), rest...)
return file, uint64(len(host))
}
// RestIn returns the rest of the envelope that the locator describes from the
// resource host, which starts at the offset of the address: only RestSize
// bytes are read, whatever follows (spec §44.1).
func (l *Locator) RestIn(host []byte, offset uint64) ([]byte, error) {
if offset > uint64(len(host)) || l.RestSize > uint64(len(host))-offset {
return nil, fmt.Errorf("locator: the resource has %d bytes, and the rest is %d from %d", len(host), l.RestSize, offset)
}
return bytes.Clone(host[offset : offset+l.RestSize]), nil
}

Powered by TurnKey Linux.