krnl

package
v0.0.0-...-eb8cb98 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kernel

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

Kernel represents the core of an address for content-addressing, such as with a content-addressable-storage.

Example

For example, imagine we had a document with just the following content:

Hello world!

(We can do content-addressing in different ways. One way to do content-addressing is using cryptographic hash functions. It isn't the only way to do content-addressing. But it is the way we will use in this example.)

(There are many different cryptographic hash functions. For the sake of this example, we will have to pick a cryptographic hash function to use. In this example we will pick the SHA3-512 cryptographic hash function.)

And also, for example, we will use the SHA3-512 cryptographic hash function for content-addressing — then the digest, from the SHA3-512 cryptographic hash function, of the document with the content "Hello world!" would be:

[]byte{
	0x95, 0xde, 0xcc, 0x72, 0xf0, 0xa5, 0x0a, 0xe4,
	0xd9, 0xd5, 0x37, 0x8e, 0x1b, 0x22, 0x52, 0x58,
	0x7c, 0xfc, 0x71, 0x97, 0x7e, 0x43, 0x29, 0x2c,
	0x8f, 0x1b, 0x84, 0x64, 0x82, 0x48, 0x50, 0x9f,
	0x1b, 0xc1, 0x8b, 0xc6, 0xf0, 0xb0, 0xd0, 0xb8,
	0x60, 0x6a, 0x64, 0x3e, 0xff, 0x61, 0xd6, 0x11,
	0xae, 0x84, 0xe6, 0xfb, 0xd4, 0xa2, 0x68, 0x31,
	0x65, 0x70, 0x6b, 0xd6, 0xfd, 0x48, 0xb3, 0x34,
}

This digest is the kernel, in this example.

(We call this a “kernel” rather than a “digest” as technically, content-addressing could be done with a different technique, other than a cryptographic hash function. And although a cryptographic hash function produces a digest, other techniques might not.)

One thing to note is that the kernel does not make note that the SHA3-512 was used to generate this digest. I.e., with just the kernel by itself, you probably have no idea what type of data is inside of it.

To store the kernel with the a note about, for example, which cryptographic hash function that was used to generate it, use addr.Address. (addr.Address contains a krnl.Kernel)

Another thing to note is that, when the kernel represents a number, the kernel does not make note of the endianness that the bytes are stored. So, it does not specify whether they in little-endian or big-endian.

func (Kernel) Bytes

func (receiver Kernel) Bytes() []byte

Bytes returns the kernel as []byte.

Note that you cannot change the bytes that are actually in the kernel by changing the bytes returned by Bytes.

This is how one might use it:

var kernel krnl.Kernel

// ...

err := kernel.Parse("ld7McvClCuTZ1TeOGyJSWHz8cZd-QyksjxuEZIJIUJ8bwYvG8LDQuGBqZD7_YdYRroTm-9SiaDFlcGvW_UizNA", "base64url")

// ...

var p []byte = kernel.Bytes()

func (Kernel) MarshalBinary

func (receiver Kernel) MarshalBinary() ([]byte, error)

MarshalBinary returns the value of Kernel as a []byte.

MarshalBinary also makes krnl.Kernel fit the encoding.BinaryMarshaler interface.

func (*Kernel) Parse

func (receiver *Kernel) Parse(value string, format string) error

Parse loads Kernel with the value parsed from ‘value’ using the parsing algoritm specified by ‘format’.

For example:

var kernel krnl.Kernel

// ...

var value string = "ld7McvClCuTZ1TeOGyJSWHz8cZd-QyksjxuEZIJIUJ8bwYvG8LDQuGBqZD7_YdYRroTm-9SiaDFlcGvW_UizNA"
var format string = "base64url"

// ...

err := kernel.Parse(value, format)

Some of the formats that Parse supports is:

• asci85

• base32

• base64

• base64url

• hexadecimal

func (*Kernel) Scan

func (receiver *Kernel) Scan(src interface{}) error

Scan assigns a value to a kernel.

Scan accepted the following types for 'src':

• []byte

• string

Scan also makes krnl.Kernel fit the sql.Scanner interface.

This is how one might use it:

var kernel krnl.Kernel

// ...

var p []byte = []byte{
	0x95, 0xde, 0xcc, 0x72, 0xf0, 0xa5, 0x0a, 0xe4,
	0xd9, 0xd5, 0x37, 0x8e, 0x1b, 0x22, 0x52, 0x58,
	0x7c, 0xfc, 0x71, 0x97, 0x7e, 0x43, 0x29, 0x2c,
	0x8f, 0x1b, 0x84, 0x64, 0x82, 0x48, 0x50, 0x9f,
	0x1b, 0xc1, 0x8b, 0xc6, 0xf0, 0xb0, 0xd0, 0xb8,
	0x60, 0x6a, 0x64, 0x3e, 0xff, 0x61, 0xd6, 0x11,
	0xae, 0x84, 0xe6, 0xfb, 0xd4, 0xa2, 0x68, 0x31,
	0x65, 0x70, 0x6b, 0xd6, 0xfd, 0x48, 0xb3, 0x34,
}

// ...

err := kernel.Scan(p)

func (Kernel) String

func (receiver Kernel) String() string

String returns the value of the kernel in base64url format.

So, for example, if the logical value of the kernel is:

[]byte{
	0x95, 0xde, 0xcc, 0x72, 0xf0, 0xa5, 0x0a, 0xe4,
	0xd9, 0xd5, 0x37, 0x8e, 0x1b, 0x22, 0x52, 0x58,
	0x7c, 0xfc, 0x71, 0x97, 0x7e, 0x43, 0x29, 0x2c,
	0x8f, 0x1b, 0x84, 0x64, 0x82, 0x48, 0x50, 0x9f,
	0x1b, 0xc1, 0x8b, 0xc6, 0xf0, 0xb0, 0xd0, 0xb8,
	0x60, 0x6a, 0x64, 0x3e, 0xff, 0x61, 0xd6, 0x11,
	0xae, 0x84, 0xe6, 0xfb, 0xd4, 0xa2, 0x68, 0x31,
	0x65, 0x70, 0x6b, 0xd6, 0xfd, 0x48, 0xb3, 0x34,
}

Then this .String() method would return:

ld7McvClCuTZ1TeOGyJSWHz8cZd-QyksjxuEZIJIUJ8bwYvG8LDQuGBqZD7_YdYRroTm-9SiaDFlcGvW_UizNA

As an aside, one could parse this into a Kernel with:

var value string = "ld7McvClCuTZ1TeOGyJSWHz8cZd-QyksjxuEZIJIUJ8bwYvG8LDQuGBqZD7_YdYRroTm-9SiaDFlcGvW_UizNA"

err := kernel.Parse(value, "base64url")

String also makes krnl.Kernel fit the fmt.Stringer interface.

That means it is likely one would indirectly call the .String() method when using fmt.Fprintf() fmt.Printf(), fmt.Sprintf().

func (*Kernel) UnmarshalBinary

func (receiver *Kernel) UnmarshalBinary(p []byte) error

UnmarshalBinary loads Kernel with the value of the []byte.

UnmarshalBinary also makes krnl.Kernel fit the encoding.BinaryUnmarshaler interface.

For example:

var kernel krnl.Kernel

// ...

var p []byte = ??? //@TODO

// ...

err := kernel.UnmarshalBinary(p)

UnmarshalBinary also makes krnl.Kernel fit the encoding.BinaryUnmarshaler interface.

Jump to

Keyboard shortcuts

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