anonymize

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: Apache-2.0 Imports: 4 Imported by: 10

Documentation

Overview

Example
package main

import (
	"log"
	"net"

	"github.com/m-lab/go/anonymize"
)

func main() {
	ip := net.ParseIP("10.10.4.3")
	anon := anonymize.New(anonymize.IPAnonymizationFlag)
	anon.IP(ip)
	log.Println(ip) // Should be "10.10.4.0" if the --anonymize.ip=netblock command-line flag was passed.
}

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Netblock causes IPv4 addresses to be anonymized up to the
	// /24 level and IPv6 addresses to the /64 level.
	Netblock = Method("netblock")

	// None performs no anonymization. By creating an anonymizer that performs
	// no anonymization, we make it possible to always have the anonymizer code
	// path be used, whether anonymization is actually needed or not, preventing
	// the creation of hundreds of needless `if shouldAnonymize {...}` code
	// blocks.
	None = Method("none")

	// IPAnonymizationFlag is a flag that determines whether IP anonymization is
	// on or off. Its value should be fixed for the duration of a program. This
	// library is not guaranteeed to work properly if you keep switching back
	// and forth between different anonymization schemes. The default is no
	// anonymization.
	IPAnonymizationFlag = None
)

Functions

This section is empty.

Types

type IPAnonymizer

type IPAnonymizer interface {
	IP(ip net.IP)
}

IPAnonymizer is the generic interface for all systems that try and ensure IP addresses are not human identifiers. It is a problem with many potential subtleties, so we permit multiple implementations. We anonymize the address in-place. If you don't want the address to be modified, then make a copy before you pass it in.

func New

func New(method Method) IPAnonymizer

New is an IP anonymization factory function that expects you to pass in anonymize.IPAnonymizationFlag, which contains the contents of the `--anonymize.ip` command-line flag.

If the anonymization method is set to "netblock", then IPv4 addresses will be anonymized up to the /24 level and IPv6 addresses to the /64 level. If it is set to "none" then no anonymization will be performed. We can imagine future anonymization techniques based on k-anonymity or that completely blot out the IP. We leave room for those implementations here, but do not (yet) implement them.

A program attempting to perform IP anonymization should only ever create one IPAnonymizer and use that one anonymizer for all connections. Otherwise, the created IPAnonymizer will lack the necessary context to correctly perform k-anonymization.

type Method

type Method string

Method is an enum suitable for using as a command-line flag. It allows only a finite set of values. We can imagine future anonymization techniques based on k-anonymity or that completely blot out the IP. We leave room for those implementations here, but do not (yet) implement them.

func (Method) Get

func (m Method) Get() interface{}

Get is required for all flag.Flag values.

func (*Method) Set

func (m *Method) Set(s string) error

Set is required for all flag.Flag values.

func (Method) String

func (m Method) String() string

String is required for all flag.Flag values.

Jump to

Keyboard shortcuts

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