Skip to content

This library provides various types to facilitate the protection of sensitive data that should not be exposed.

License

Notifications You must be signed in to change notification settings

coopnorge/go-masker-lib

Repository files navigation

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

About

This library provides various types to facilitate the protection of sensitive data that should not be exposed.

Resources

License

Stars

Watchers

Forks

Packages

No packages published