internal

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CRC24Polynomial = uint32(0x864CFB) // CRC-24 polynomial
	CRC24Initial    = uint32(0xB704CE) // Initial value
	CRC24TableSize  = uint32(256)      // Table size for faster computation
)
View Source
const (
	BytesPerLine = 22 // As is done in paperkey (https://www.jabberwocky.com/software/paperkey/)
	PdfTextFont  = "Text"
	PdfMonoFont  = "Mono"
)
View Source
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

View Source
var (
	PdfTextFontRegularBytes []byte
	PdfTextFontBoldBytes    []byte
	PdfTextFontItalicBytes  []byte
)
View Source
var (
	PdfMonoFontRegularBytes []byte
	PdfMonoFontBoldBytes    []byte
	PdfMonoFontItalicBytes  []byte
)
View Source
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
)
View Source
var VersionInfo goversion.Info

Functions

func BytesFromBase64

func BytesFromBase64(data string) ([]byte, error)

func CloseFileIfNotStd added in v1.1.1

func CloseFileIfNotStd(file *os.File) error

func Crc24Checksum

func Crc24Checksum(data []byte) uint32

func DeserializeBinary

func DeserializeBinary(data *[]byte) ([]byte, error)

func GeneratePassphraseSheetPDF

func GeneratePassphraseSheetPDF(seed int64, words []string) ([]byte, error)

func GenerateSerial

func GenerateSerial(length uint8) (string, error)

GenerateSerial generates a random serial number of length `length`

func GetFileHandleCarefully

func GetFileHandleCarefully(path string, override bool) (*os.File, error)

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 ParseHexUint32(hex string) (uint32, error)

func PrintInputAndGetReader added in v1.0.1

func PrintInputAndGetReader(inFileName string) (*os.File, error)

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

func PrintInputAndRead(inFileName string) ([]byte, error)

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 PrintWrittenSize(size int, file *os.File)

func ReadTtyLine

func ReadTtyLine() ([]byte, error)

func SensitivePrompt added in v1.1.1

func SensitivePrompt() ([]byte, error)

SensitivePrompt reads a password from the tty (if available) or stdin (if not).

func SerializeBinary

func SerializeBinary(data *[]byte) string

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 SliceHasString(slice []string, str string) bool

func SprintBinarySize

func SprintBinarySize(size int) string

func SprintBinarySize64

func SprintBinarySize64(size int64) string

func ValidateCRC24

func ValidateCRC24(data []byte, checksum uint32) bool

func ValidateCRC32

func ValidateCRC32(data []byte, checksum uint32) bool

Types

type LineData

type LineData struct {
	LineNumber uint32
	Data       []byte
	CRC24      uint32
}

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.

func (*PaperCrypt) GetText

func (p *PaperCrypt) GetText(lowerCaseEncoding bool) ([]byte, error)

GetText returns the text representation of the paper crypt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL