age

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package age provides a wrapper for "gopkg.in/yaml.v3" to decrypt age encrypted data when Unmarshalling and encrypting data when Marshalling.

Decoding

See https://github.com/sylr/go-yaml-crypto/blob/master/age/examples/decode.go

Encoding

See https://github.com/sylr/go-yaml-crypto/blob/master/age/examples/encode.go

Index

Constants

View Source
const (
	// YAMLTag tag that is used to identify data to crypt/decrypt
	YAMLTag = "!crypto/age"
)

Variables

This section is empty.

Functions

func MarshalYAML

func MarshalYAML(node *yaml.Node, recipients []age.Recipient) (*yaml.Node, error)

MarshalYAML takes a *yaml.Node and []age.Recipient and recursively encrypt/marshal the Values.

Types

type ArmoredString

type ArmoredString struct {
	Value      string
	Recipients []age.Recipient
}

ArmoredString is a struct holding the string to encrypt and the intended recipients.

func (ArmoredString) MarshalYAML

func (a ArmoredString) MarshalYAML() (interface{}, error)

MarshalYAML encrypts the ArmoredString and marshals it to YAML. If Recipients is empty then the Value is kept unencrypted.

func (*ArmoredString) String

func (a *ArmoredString) String() string

String implements the Stringer interface.

func (*ArmoredString) UnmarshalYAML

func (a *ArmoredString) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML pushes the yaml.Node.Value in the ArmoredString.Value.

type Wrapper

type Wrapper struct {
	// Value holds the struct that will be decrypted with the Identities.
	Value interface{}
	// Identities that will be used for decrypting.
	Identities []age.Identity
}

Wrapper is a struct that allows to decrypt crypted armored data in YAML as long that the data is tagged with "!crypto/age".

database_login: mylogin
database_password: !crypto/age |
  -----BEGIN AGE ENCRYPTED FILE-----
  ...
  ...
  -----END AGE ENCRYPTED FILE-----

Example:

bytes := []byte(...)
node := struct {
	Key1 string `yaml:"key1"`
	Key2 string `yaml:"key2"`
}{}
w := Wrapper{
	Value:      &node,
	Identities: []age.Indentity{...},
}
decoder := yaml.NewDecoder(in)
err := decoder.Decode(&w)

If you intend to only display the YAML data with unencryted values you should use `&yaml.Node{}` as `Wrapper.Value` so you can marshal it later with comments.

func (Wrapper) UnmarshalYAML

func (w Wrapper) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML takes yaml.Node and recursively decrypt data marked with the !crypto/age YAML tag.

Jump to

Keyboard shortcuts

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