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 ¶
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 ¶
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.