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 GeneratePassphraseSheetPDF(seed int64, words []string) ([]byte, error)
- func GenerateSerial(length uint8) (string, error)
- func GetFileHandleCarefully(path string, override bool) (*os.File, error)
- 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) string
- func SliceHasString(slice []string, str string) bool
- func SprintBinarySize(size int) string
- func SprintBinarySize64(size int64) string
- func ValidateCRC24(data []byte, checksum uint32) bool
- func ValidateCRC32(data []byte, checksum uint32) bool
- type LineData
- type PaperCrypt
Constants ¶
const ( CRC24Polynomial = uint32(0x864CFB) // CRC-24 polynomial CRC24Initial = uint32(0xB704CE) // Initial value CRC24TableSize = uint32(256) // Table size for faster computation )
const ( BytesPerLine = 22 // As is done in paperkey (https://www.jabberwocky.com/software/paperkey/) PdfTextFont = "Text" PdfMonoFont = "Mono" )
const ( HeaderFieldVersion = "PaperCrypt Version" HeaderFieldSerial = "Content Serial" HeaderFieldPurpose = "Purpose" HeaderFieldComment = "Comment" HeaderFieldDate = "Date" 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 = "" /* 511-byte string literal not displayed */ PDFSectionRecoveryHeading = "Recovering the data" PDFSectionRecoveryContent = "" /* 251-byte string literal not displayed */ PDFSectionRecoveryContentNoQR = "" /* 230-byte string literal not displayed */ )
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 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 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 SliceHasString ¶
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 // Data is the encrypted data as a PGP message Data *crypto.PGPMessage // SerialNumber is the serial number of document, used to identify it. It is generated randomly if not provided. SerialNumber string // Purpose is the purpose of document Purpose string // Comment is the comment on document Comment string // CreatedAt is the creation timestamp CreatedAt time.Time // DataCRC24 is the CRC-24 checksum of the encrypted data DataCRC24 uint32 // DataCRC32 is the CRC-32 checksum of the encrypted data DataCRC32 uint32 // DataSHA256 is the SHA-256 checksum of the encrypted data DataSHA256 [32]byte }
func NewPaperCrypt ¶
func NewPaperCrypt(version string, data *crypto.PGPMessage, serialNumber string, purpose string, comment string, createdAt time.Time) *PaperCrypt
NewPaperCrypt creates a new paper crypt
func (*PaperCrypt) GetBinary ¶
func (p *PaperCrypt) GetBinary() []byte
func (*PaperCrypt) GetBinarySerialized ¶
func (p *PaperCrypt) GetBinarySerialized() string
func (*PaperCrypt) GetLength ¶
func (p *PaperCrypt) GetLength() int
func (*PaperCrypt) GetPDF ¶
func (p *PaperCrypt) GetPDF(noQR 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 QR-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 QR code containing the encrypted data.