code

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

Verification Code - Library

A Golang Library for calculating File Verification Codes.

  • Version 2 - Version 2 is a SHA256 with the file signature 'FVC2' + Null. So a hex-encoded Version 2 file verification code using the empty SHA256 would be:
4656433200e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

Getting started

What's contained in this project

  • legacy - contains the following:
    • legacy.go - src code for version 0
    • upgrade.go - upgrading version 0 to version 1
    • valid.go - src code for validating
  • enum.go - custom type for versions
  • v1.go - src code for version 1
  • v2.go - src code for version 2
  • version.go - checking version of Hex string or bytes

Algorithm

  • Collect a list of every regular file in your collection.
    • Ignore: directories, Named Pipes, Sockets, Block Device Files, Character Device Files, or Symbolic Links.
  • Calculate the sha256 of every file.
  • Sort, ascending, the list of sha256s.
  • Calculate the sha256 of the list of sha256s.
  • Append 'FVC2' + Null to the front of this sha256 and return.

Documentation

Overview

Copyright (c) 2020 Wind River Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Copyright (c) 2020 Wind River Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Copyright (c) 2020 Wind River Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewVersionTwo

func NewVersionTwo() hasher.FileCollectionHasher

Types

type Version

type Version uint8
const (
	VERSION_TWO Version = 2
)

func VersionOf

func VersionOf(b []byte) (*Version, error)

VersionOf checks the slice of bytes to figure out the version of fvc used and returns the version and error

func VersionOfHex

func VersionOfHex(s string) (*Version, error)

VersionOfHex checks the hex string to figure out the version of fvc used and returns the version and error

type VersionTwoHasher

type VersionTwoHasher struct {
	// contains filtered or unexported fields
}

func (*VersionTwoHasher) AddSha256

func (h *VersionTwoHasher) AddSha256(b []byte) error

AddSha256 is used to add a file's SHA256 from the slice of bytes when the data used is the metadata from the database instead of the directory of file, returns an error in case of failure.

func (*VersionTwoHasher) AddSha256Hex

func (h *VersionTwoHasher) AddSha256Hex(s string) error

AddSha256Hex is used to add a file's SHA256 from the hex string when the data used is the metadata from the database instead of the directory of file, returns an error in case of failure.

func (VersionTwoHasher) Hex

func (h VersionTwoHasher) Hex() string

Hex converts the fvc from slice of bytes to hex string

func (*VersionTwoHasher) ReadFile

func (h *VersionTwoHasher) ReadFile(r io.Reader) error

ReadFile is used to take in a parameter of type io.Reader as input, calculate the SHA256 of the file and adding it to the list, returns an error in case of failure

func (VersionTwoHasher) Sum

func (h VersionTwoHasher) Sum() []byte

Sum is used to sort the list of files and calculating the SHA1 of the list and returns the fvc as a slice of bytes

Jump to

Keyboard shortcuts

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