masker

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 2 Imported by: 0

README

Masker library 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 by masking the data in situations that would result in exposure such as string formatting, logging and marshalling to JSON or YAML.

Type Protection Strategy
CensoredString Protects the a value by masking it with a constant value.

Using CensoredString

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

package example

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

	"github.com/coopnorge/go-masker-lib"
	"github.com/stretchr/testify/assert"
)

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

	// masker.CensoredString can be used to protect sensitive or secret values.
	protectedValue := masker.CensoredString(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.UnmaskString()), secretValue)
}

Developing

# build images
docker-compose build
# see available targets
docker-compose run --rm golang-devtools make help
# validate
docker-compose run --rm golang-devtools make validate VERBOSE=all
# run in watch mode
docker-compose run --rm golang-devtools make watch

Documentation

Overview

Package masker provides Go types which makes it easy to protect sensitive data from exposure by masking the data in situations that would result in exposure such as string formatting, logging and marshalling to JSON or YAML.

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 CensoredString

type CensoredString string

CensoredString masks a string value by censoring it when it printed or marshalled to JSON, YAML or Text. The protected value can be revealed by calling the UnmaskString() method on the CensoredString value.

func (CensoredString) GoString

func (s CensoredString) GoString() string

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

func (CensoredString) MarshalText

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

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

func (CensoredString) String

func (s CensoredString) String() string

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

func (CensoredString) UnmaskString

func (s CensoredString) UnmaskString() string

UnmaskString returns the underlying protected string of a CensoredString value.

type StringUnmasker

type StringUnmasker interface {
	UnmaskString() string
}

StringUnmasker is an interface that provides a method for revealing masked strings.

Jump to

Keyboard shortcuts

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