HomeUniDoc
HomeUniDoc
...

Package redactor

Overview ▾

Constants

Widely used regex patterns #nosec G101 - these are regular expressions, and not credentials

const (
    RegexSSN                = `(?i)\b\d{3}-\d{2}-\d{4}\b`
    RegexCreditCard         = `\b(?:\d[ -]*?){13,16}\b`
    RegexEmail              = `\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b`
    RegexPhone              = `(?:\+1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}`
    RegexIPv4               = `\b(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\b`
    RegexIPv6               = `\b([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b`
    RegexPassport           = `\b[A-Z0-9]{6,9}\b`
    RegexDriversLicense     = `\b[A-Z0-9]{5,15}\b`
    RegexDate               = `\b(?:\d{1,2}[/.-]\d{1,2}[/.-]\d{2,4}|\d{4}[-/]\d{2}[-/]\d{2})\b`
    RegexPostalCode         = `\b\d{5}(?:-\d{4})?\b`
    RegexMAC                = `\b(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\b`
    RegexBankRouting        = `\b\d{9}\b`
    RegexIBAN               = `\b[A-Z]{2}\d{2}[A-Z0-9]{11,30}\b`
    RegexAWSAccessKeyID     = `\bAKIA[0-9A-Z]{16}\b`
    RegexAWSSecretAccessKey = `\b[0-9a-zA-Z/+]{40}\b`
    RegexGoogleAPIKey       = `\bAIza[0-9A-Za-z\-_]{35}\b`
    RegexJWT                = `\beyJ[A-Za-z0-9_\-]+\.eyJ[A-Za-z0-9_\-]+\.?[A-Za-z0-9_\-]*\b`
    RegexCardExpirationDate = `\b(0[1-9]|1[0-2])/(?:\d{2}|\d{4})\b`
    RegexSWIFTCode          = `\b[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?\b`
    RegexStripeAPIKey       = `sk_live_[0-9a-zA-Z]{24}`
)

Variables

List of regex patterns

var StandardRegexPatterns = []string{
    RegexSSN,
    RegexCreditCard,
    RegexEmail,
    RegexPhone,
    RegexIPv4,
    RegexIPv6,
    RegexPassport,
    RegexDriversLicense,
    RegexDate,
    RegexPostalCode,
    RegexMAC,
    RegexBankRouting,
    RegexIBAN,
    RegexAWSAccessKeyID,
    RegexAWSSecretAccessKey,
    RegexGoogleAPIKey,
    RegexJWT,
    RegexCardExpirationDate,
    RegexSWIFTCode,
    RegexStripeAPIKey,
}

type RectangleProps

RectangleProps defines properties of the redaction rectangle to be drawn.

type RectangleProps struct {
    FillColor   creator.Color // fill color of the rectangle.
    BorderWidth float64       // a floating number that determines the border width.
    FillOpacity float64       // a floating number that determines the opacity of the rectangle as a fraction of 1.
}

func RedactRectanglePropsNew

func RedactRectanglePropsNew() *RectangleProps

RedactRectanglePropsNew return a new pointer to a default RectangleProps object.

type RedactionOptions

RedactionOptions is a collection of RedactionTerm objects.

type RedactionOptions struct {
    Terms               []RedactionTerm
    UseStandardPatterns bool
}

type RedactionTerm

RedactionTerm holds the regexp pattern and the replacement string for the redaction process.

type RedactionTerm struct {
    Pattern *regexp.Regexp
}

type Redactor

Redactor represents a Redactor object.

type Redactor struct {
    // contains filtered or unexported fields
}

func New

func New(reader *model.PdfReader, opts *RedactionOptions, rectProps *RectangleProps) *Redactor

New instantiates a Redactor object with given PdfReader and `regex` pattern.

func (*Redactor) Redact

func (re *Redactor) Redact() error

Redact executes the redact operation on a pdf file and updates the content streams of all pages of the file.

func (*Redactor) Write

func (re *Redactor) Write(writer io.Writer) error

Write writes the content of `re.creator` to writer of type io.Writer interface.

func (*Redactor) WriteToFile

func (re *Redactor) WriteToFile(outputPath string) error

WriteToFile writes the redacted document to file specified by `outputPath`.