Documentation ¶
Index ¶
- Constants
- Variables
- func BytesFromBase64(data string) ([]byte, error)
- func CloseFileIfNotStd(file *os.File) error
- func Crc24Checksum(data []byte) uint32
- func DeserializeBinary(data *[]byte) ([]byte, error)
- func GenerateFromSeed(seed int64, amount int, wordList *[]string) ([]string, error)
- func GeneratePassphraseSheetPDF(seed int64, words []string) ([]byte, error)
- func GenerateSerial(length uint8) (string, error)
- func GetFileHandleCarefully(path string, override bool) (*os.File, error)
- func NormalizeLineEndings(data []byte) []byte
- func ParseHexUint32(hex string) (uint32, error)
- func PrintInputAndGetReader(inFileName string) (*os.File, error)
- func PrintInputAndRead(inFileName string) ([]byte, error)
- func PrintWrittenSize(size int, file *os.File)
- func ReadTtyLine() ([]byte, error)
- func SensitivePrompt() ([]byte, error)
- func SerializeBinary(data *[]byte, bytesPerLine int) string
- func SerializeBinaryV1(data *[]byte) string
- func SerializeBinaryV2(data *[]byte) string
- func SliceHasString(slice []string, str string) bool
- func SplitTextHeaderAndBody(data []byte) ([]byte, []byte, error)
- func SprintBinarySize(size int) string
- func SprintBinarySize64(size int64) string
- func TextToHeaderMap(text []byte) (map[string]string, error)
- func ValidateCRC24(data []byte, checksum uint32) bool
- func ValidateCRC32(data []byte, checksum uint32) bool
- type LineData
- type PaperCrypt
- func DeserializeV1Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMismatch bool) (*PaperCrypt, error)
- func DeserializeV2Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMismatch bool) (*PaperCrypt, error)
- func NewPaperCrypt(version string, data []byte, serialNumber string, purpose string, ...) *PaperCrypt
- func (p *PaperCrypt) Decode(passphrase []byte) ([]byte, error)
- func (p *PaperCrypt) GetBinarySerialized() (string, error)
- func (p *PaperCrypt) GetDataLength() int
- func (p *PaperCrypt) GetPDF(no2D bool, lowerCaseEncoding bool) ([]byte, error)
- func (p *PaperCrypt) GetText(lowerCaseEncoding bool) ([]byte, error)
- func (p *PaperCrypt) MarshalJSON() ([]byte, error)
- func (p *PaperCrypt) UnmarshalJSON(data []byte) error
- type PaperCryptContainerVersion
- type PaperCryptDataFormat
- type PaperCryptV1
Constants ¶
const ( BytesPerLine = 24 PdfTextFont = "Text" PdfMonoFont = "Mono" PdfDataLineFontSize = 11 )
const ( HeaderFieldVersion = "PaperCrypt Version" HeaderFieldSerial = "Content Serial" HeaderFieldPurpose = "Purpose" HeaderFieldComment = "Comment" HeaderFieldDate = "Date" HeaderFieldDataFormat = "Data Format" HeaderFieldContentLength = "Content Length" HeaderFieldCRC24 = "Content CRC-24" HeaderFieldCRC32 = "Content CRC-32" HeaderFieldSHA256 = "Content SHA-256" HeaderFieldHeaderCRC32 = "Header CRC-32" PDFHeaderSheetID = "Sheet ID" PDFHeading = "PaperCrypt Recovery Sheet" PDFSectionDescriptionHeading = "What is this?" PDFSectionDescriptionContent = "" /* 235-byte string literal not displayed */ PDFSectionRepresentationHeading = "Binary Data Representation" PDFSectionRepresentationContent = "" /* 556-byte string literal not displayed */ PDFSectionRecoveryHeading = "Recovering the data" PDFSectionRecoveryContent = "" /* 251-byte string literal not displayed */ PDFSectionRecoveryContentNo2D = "" /* 230-byte string literal not displayed */ )
const ( CRC24Polynomial = uint32(0x864CFB) // CRC-24 polynomial CRC24Initial = uint32(0xB704CE) // Initial value CRC24TableSize = uint32(256) // Table size for faster computation )
const ( TimeStampFormatLong = "Mon, 02 Jan 2006 15:04:05.000000000 -0700" TimeStampFormatLongTZ = "Mon, 02 Jan 2006 15:04:05.000000000 MST" TimeStampFormatShort = "2006-01-02 15:04:05" TimeStampFormatDate = "2006-01-02" TimeStampFormatPDFHeader = "2006-01-02 15:04 -0700" )
const (
BytesPerLineV1 = 22 // As is done in paperkey (https://www.jabberwocky.com/software/paperkey/)
)
Variables ¶
var ( PdfTextFontRegularBytes []byte PdfTextFontBoldBytes []byte PdfTextFontItalicBytes []byte )
var ( PdfMonoFontRegularBytes []byte PdfMonoFontBoldBytes []byte PdfMonoFontItalicBytes []byte )
var ( // URL is used to style URLs. URL = lipgloss.NewStyle().Foreground(lipgloss.Color("3")).Render // Warning is used to style warnings for the user. Warning = lipgloss.NewStyle().Foreground(lipgloss.Color("11")).Bold(true).Render Bold = lipgloss.NewStyle().Bold(true).Render )
var VersionInfo goversion.Info
Functions ¶
func BytesFromBase64 ¶
func CloseFileIfNotStd ¶ added in v1.1.1
func Crc24Checksum ¶
func DeserializeBinary ¶
func GenerateFromSeed ¶ added in v1.4.0
func GenerateSerial ¶
GenerateSerial generates a random serial number of length `length`.
func GetFileHandleCarefully ¶
GetFileHandleCarefully returns a file handle for the given path. will warn if the file already exists, and error if override is false. if path is empty, returns os.Stdout.
func NormalizeLineEndings ¶ added in v1.4.0
func ParseHexUint32 ¶
func PrintInputAndGetReader ¶ added in v1.0.1
PrintInputAndGetReader prints the input source and returns the reader. if path is empty, returns os.Stdin. must be closed by the caller.
func PrintInputAndRead ¶ added in v1.0.1
PrintInputAndRead prints the input source and returns the contents of the file. if path is empty, returns os.Stdin.
func PrintWrittenSize ¶ added in v1.0.1
func ReadTtyLine ¶
func SensitivePrompt ¶ added in v1.1.1
SensitivePrompt reads a password from the tty (if available) or stdin (if not).
func SerializeBinary ¶
SerializeBinary returns the encrypted binary data, formatted for restoration lines will hold 22 bytes of data, prefaces by the line number, followed by the CRC-24 of the line, bytes are printed as two base16 (hex) digits, separated by a space. Example:
1: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 <CRC-24 of this line> 2: ... <CRC-24 of this line>
10: ... <CRC-24 of this line> ... n-1: ... <CRC-24 of this line> n: <CRC-24 of the block>
See [example.pdf](example.pdf) for an example.
func SerializeBinaryV1 ¶ added in v1.4.0
SerializeBinaryV1 serializes binary data using SerializeBinary.
func SerializeBinaryV2 ¶ added in v1.4.0
SerializeBinaryV2 serializes binary data using SerializeBinary.
func SliceHasString ¶
func SplitTextHeaderAndBody ¶ added in v1.4.0
func SprintBinarySize ¶
func SprintBinarySize64 ¶
func ValidateCRC24 ¶
func ValidateCRC32 ¶
Types ¶
type PaperCrypt ¶
type PaperCrypt struct { // Version is the version of papercrypt used to generate the document. Version string `json:"v"` // DataFormat determines whether the data is raw (although still gzipped), or follows the PGP message format (gzipped). DataFormat PaperCryptDataFormat `json:"f"` // SerialNumber is the serial number of document, used to identify it. It is generated randomly if not provided. SerialNumber string `json:"sn"` // Purpose is the purpose of document Purpose string `json:"p"` // Comment is the comment on document Comment string `json:"cm"` // CreatedAt is the creation timestamp CreatedAt time.Time `json:"ct"` // DataCRC24 is the CRC-24 checksum of the encrypted data DataCRC24 uint32 `json:"d_c24"` // DataCRC32 is the CRC-32 checksum of the encrypted data DataCRC32 uint32 `json:"d_c32"` // DataSHA256 is the SHA-256 checksum of the encrypted data DataSHA256 [32]byte `json:"d_s256"` // Data is the contents of the document // it can be either of two formats: // a) ASCII armored OpenPGP data, if DataFormat is PGP // the contained message is gzipped before encryption // b) Raw data of any kind, if DataFormat is Raw // either way, data is always gzipped after processing Data []byte `json:"d"` }
func DeserializeV1Text ¶ added in v1.4.0
func DeserializeV1Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMismatch bool) (*PaperCrypt, error)
func DeserializeV2Text ¶ added in v1.4.0
func DeserializeV2Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMismatch bool) (*PaperCrypt, error)
func NewPaperCrypt ¶
func NewPaperCrypt(version string, data []byte, serialNumber string, purpose string, comment string, createdAt time.Time, format PaperCryptDataFormat) *PaperCrypt
NewPaperCrypt creates a new paper crypt.
func (*PaperCrypt) Decode ¶ added in v1.4.0
func (p *PaperCrypt) Decode(passphrase []byte) ([]byte, error)
func (*PaperCrypt) GetBinarySerialized ¶
func (p *PaperCrypt) GetBinarySerialized() (string, error)
func (*PaperCrypt) GetDataLength ¶ added in v1.4.0
func (p *PaperCrypt) GetDataLength() int
func (*PaperCrypt) GetPDF ¶
func (p *PaperCrypt) GetPDF(no2D bool, lowerCaseEncoding bool) ([]byte, error)
GetPDF returns the binary representation of the paper crypt The PDF will be generated to include some basic information about papercrypt, some metadata, optionally a 2D-Code, and the encrypted data.
The data will be formatted as
a) ASCII armored OpenPGP data, if --armor is specified b) Base16 (hex) encoded binary data, if --armor is not specified
The PDF Document will have a header row, containing the following information:
- Serial Number
- Creation Date
- Purpose
and, next to the markdown information, a 2D code containing the encrypted data.
func (*PaperCrypt) GetText ¶
func (p *PaperCrypt) GetText(lowerCaseEncoding bool) ([]byte, error)
GetText returns the text representation of the paper crypt.
func (*PaperCrypt) MarshalJSON ¶ added in v1.4.0
func (p *PaperCrypt) MarshalJSON() ([]byte, error)
func (*PaperCrypt) UnmarshalJSON ¶ added in v1.4.0
func (p *PaperCrypt) UnmarshalJSON(data []byte) error
type PaperCryptContainerVersion ¶ added in v1.4.0
type PaperCryptContainerVersion uint32
const ( PaperCryptContainerVersionUnknown PaperCryptContainerVersion = 0 PaperCryptContainerVersionMajor1 PaperCryptContainerVersion = 1 PaperCryptContainerVersionMajor2 PaperCryptContainerVersion = 2 PaperCryptContainerVersionDevel PaperCryptContainerVersion = PaperCryptContainerVersion(0xFFFFFFFF) )
func PaperCryptContainerVersionFromString ¶ added in v1.4.0
func PaperCryptContainerVersionFromString(s string) PaperCryptContainerVersion
func (PaperCryptContainerVersion) String ¶ added in v1.4.0
func (v PaperCryptContainerVersion) String() string
type PaperCryptDataFormat ¶ added in v1.4.0
type PaperCryptDataFormat uint8
const ( PaperCryptDataFormatPGP PaperCryptDataFormat = 0 PaperCryptDataFormatRaw PaperCryptDataFormat = 1 )
func PaperCryptDataFormatFromString ¶ added in v1.4.0
func PaperCryptDataFormatFromString(s string) PaperCryptDataFormat
func (PaperCryptDataFormat) String ¶ added in v1.4.0
func (f PaperCryptDataFormat) String() string
type PaperCryptV1 ¶ added in v1.4.0
type PaperCryptV1 struct { // Version is the version of papercrypt used to generate the document. Version string `json:"Version"` // Data is the encrypted data as a PGP message Data *crypto.PGPMessage `json:"Data"` // SerialNumber is the serial number of document, used to identify it. It is generated randomly if not provided. SerialNumber string `json:"SerialNumber"` // Purpose is the purpose of document Purpose string `json:"Purpose"` // Comment is the comment on document Comment string `json:"Comment"` // CreatedAt is the creation timestamp CreatedAt time.Time `json:"CreatedAt"` // DataCRC24 is the CRC-24 checksum of the encrypted data DataCRC24 uint32 `json:"DataCRC24"` // DataCRC32 is the CRC-32 checksum of the encrypted data DataCRC32 uint32 `json:"DataCRC32"` // DataSHA256 is the SHA-256 checksum of the encrypted data DataSHA256 [32]byte `json:"DataSHA256"` }
func NewPaperCryptV1 ¶ added in v1.4.0
func NewPaperCryptV1(version string, data *crypto.PGPMessage, serialNumber string, purpose string, comment string, createdAt time.Time) *PaperCryptV1
NewPaperCryptV1 creates a new paper crypt
func (*PaperCryptV1) GetBinary ¶ added in v1.4.0
func (p *PaperCryptV1) GetBinary() []byte
func (*PaperCryptV1) GetBinarySerialized ¶ added in v1.4.0
func (p *PaperCryptV1) GetBinarySerialized() string
func (*PaperCryptV1) GetLength ¶ added in v1.4.0
func (p *PaperCryptV1) GetLength() int
func (*PaperCryptV1) GetText ¶ added in v1.4.0
func (p *PaperCryptV1) GetText(lowerCaseEncoding bool) ([]byte, error)
func (*PaperCryptV1) ToNextVersion ¶ added in v1.4.0
func (p *PaperCryptV1) ToNextVersion() (*PaperCrypt, error)
ToNextVersion converts the PaperCryptV1 to the next version, PaperCrypt, by encoding format information and compressing the data.