json

package
v0.0.0-...-0d34ca8 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2018 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package json implements functions to load the Public key data from an ecfg file, and to walk that data file, encrypting or decrypting any keys which, according to the specification, are marked as encryptable (see README.md for details).

It may be non-obvious why this is implemented using a scanner and not by loading the structure, manipulating it, then dumping it. Since Go's maps are explicitly randomized, that would cause the entire structure to be randomized each time the file was written, rendering diffs over time essentially useless.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FormatHandler

type FormatHandler struct{}

FormatHandler simply exposes the methods reqwuired of format.FormatHandler.

func (*FormatHandler) ExtractPublicKey

func (h *FormatHandler) ExtractPublicKey(data []byte) (key [32]byte, err error)

ExtractPublicKey finds the _public_key value in an ecfg document and parses it into a key usable with the crypto library.

func (*FormatHandler) TransformScalarValues

func (h *FormatHandler) TransformScalarValues(
	data []byte,
	action func([]byte) ([]byte, error),
) ([]byte, error)

TransformScalarValues walks a JSON document, replacing all actionable nodes with the result of calling the passed-in `action` parameter with the content of the node. A node is actionable if it's a string *value* or an array element, and its referencing key doesn't begin with an underscore. For each actionable node, the contents are replaced with the result of Action. Everything else is unchanged, and arbitrary document structure and formatting are preserved.

Note that this underscore-to-disable-encryption syntax does not propagate down the hierarchy to children. That is:

  • In {"_a": "b"}, Action will not be run at all.
  • In {"a": "b"}, Action will be run with "b", and the return value will replace "b".
  • In {"k": {"a": ["b"]}, Action will run on "b".
  • In {"_k": {"a": ["b"]}, Action run on "b".
  • In {"k": {"_a": ["b"]}, Action will not run.

Jump to

Keyboard shortcuts

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