core

package
v0.0.0-...-c365a6b Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-3.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateBlockHash

func CalculateBlockHash(b []byte) (string, error)

CalculateBlockHash calculates the sha1 checksum of a given byte slice b.

func CopyByteArea

func CopyByteArea(start int, end int, reader *bytes.Reader) ([]byte, error)

CopyByteArea copies an area of bytes from a reader. It verifies that the reader reads the wanted amount of bytes, and returns an error if this is not the case.

func OpenDB

func OpenDB(dbpath string, readonly bool) (*bolt.DB, error)

OpenDB opens a bbolt database and returns a bbolt instance.

func ReadBlock

func ReadBlock(node Node, part *bytes.Reader, totalReadBlocks int) ([]byte, int, error)

ReadBlock reads a data area of a bytes.Reader specified in the given node. It additionally verifies that the amount of bytes read equal the wanted amount and returns an error if this is not the case.

func ReadDB

func ReadDB(partition string) (string, error)

ReadDB reads the database from a fsverify partition. It verifies the the size of the database with the size specified in the partition header and returns an error if the sizes do not match. Due to limitations with bbolt the database gets written to a temporary path and the function returns the path to the database.

func ReadKey

func ReadKey() (string, error)

ReadKey is a wrapper function to call the proper readKey function according to config.KeyStore.

func VerifyBlock

func VerifyBlock(block []byte, node Node) error

VerifyBlock verifies a byte slice with the hash in a given Node.

func VerifyNode

func VerifyNode(node Node, nextNode Node) error

VerifyNode verifies that the current Node is valid by matching the checksum of it with the PrevNodeSum field of the next node.

func VerifySignature

func VerifySignature(key string, signature string, database string) (bool, error)

VerifySignature verifies the database using a given signature and public key.

func WarnUser

func WarnUser()

Types

type Header struct {
	MagicNumber    int
	Signature      string
	FilesystemSize int
	FilesystemUnit int
	TableSize      int
	TableUnit      int
}

Header contains all information stored in the header of a fsverify partition.

func ReadHeader

func ReadHeader(partition string) (Header, error)

ReadHeader reads the partition header and puts it in a variable of type Header. If any field fails to be read, the function returns an empty Header struct and the error.

type Node

type Node struct {
	BlockStart  int
	BlockEnd    int
	BlockSum    string
	PrevNodeSum string
}

Node contains all information stored in a database node. If the Node is the first node in the database, PrevNodeSum should be set to Entrypoint.

func GetNode

func GetNode(checksum string, db *bolt.DB) (Node, error)

GetNode retrieves a Node from the database based on the hash identifier. If db is set to nil, the function will open the database in read-only mode itself.

func (*Node) GetHash

func (n *Node) GetHash() (string, error)

GetHash returns the hash of all fields of a Node combined. The Node fields are combined in the order BlockStart, BlockEnd, BlockSum and PrevNodeSum

Jump to

Keyboard shortcuts

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