pdt

package module
v0.0.0-...-360d217 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: CC0-1.0, MIT-0 Imports: 2 Imported by: 0

README

Protected Data Types (PDT) for Go

branch status

Go Report Card codecov Godoc license

This library provides Go types which makes it easy to protect sensitive data from exposure.

Type Protection Strategy
MaskedString Protects the a value by masking it with a constant value whenever the string representation is requested or whenever it is marshalled.

Using MaskedString

The code below provides an example of how to use MaskedString:

package example

import (
	"encoding/json"
	"fmt"
	"testing"

	"github.com/iauc/pdt"
	"github.com/stretchr/testify/assert"
)

func TestMaskedString(t *testing.T) {
	secretValue := "secretvalue"

	// pdt.MaskedString can be used to protect sensitive or secret values.
	protectedValue := pdt.MaskedString(secretValue)

	// The protected value will not appear in formatted output.
	assert.NotContains(t, fmt.Sprintf("%s", protectedValue), secretValue)

	// The protected value will not appear in marshalled output.
	m, err := json.Marshal(protectedValue)
	assert.NoError(t, err)
	assert.NotContains(t, m, secretValue)

	// The underlying secret value can be revealed.
	assert.Equal(t, fmt.Sprintf("%s", protectedValue.RevealString()), secretValue)
}

Documentation

Index

Constants

View Source
const CensoredText = "###CENSORED###"

CensoredText is the text displayed instead of protected values when they are masked.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaskedString

type MaskedString string

MaskedString protects a string value by masking it when it printed or marshalled to JSON, YAML or Text. The protected value can be revealed by calling the RevealString() method on the MaskedString value.

func (MaskedString) GoString

func (s MaskedString) GoString() string

GoString returns the Go syntax for a MaskedString value, which will invariably be the Go syntax for the CensoredString constant.

func (MaskedString) MarshalText

func (s MaskedString) MarshalText() ([]byte, error)

MarshalText marshals the MaskedString value into a textual form, which will invariably be the value of the CensoredString constant.

func (MaskedString) RevealString

func (s MaskedString) RevealString() string

RevealString returns the underlying protected string of a MaskedString value.

func (MaskedString) String

func (s MaskedString) String() string

String returns the native format for a MaskedString value, which will invariably be the CensoredString constant.

type StringRevealer

type StringRevealer interface {
	RevealString() string
}

StringRevealer is an interface that provides a method for revealing protected values.

Jump to

Keyboard shortcuts

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