wfn

package
v0.0.0-...-e85a4bd Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package wfn provides a representation, bindings and matching of the Well-Formed CPE names as per https://nvlpubs.nist.gov/nistpubs/Legacy/IR/nistir7695.pdf and https://nvlpubs.nist.gov/nistpubs/Legacy/IR/nistir7696.pdf

Copyright (c) Facebook, Inc. and its affiliates.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	Any = ""
	NA  = "-"
)

Possible logical value of Attributes empty string considered ANY when parsing and unquoted "-" is illegal in WFN attribute-value

Variables

View Source
var KnownParts = map[string]string{
	"a": "application",
	"o": "operating system",
	"h": "hardware",
}

KnownParts is a map of known WFN attribute parts.

Functions

func HasWildcard

func HasWildcard(s string) bool

HasWildcard returns true if attribute has a wildcard symbol in it

func Match

func Match(src, tgt *Attributes) bool

Match returns false if the src and tgt attributes are disjoint. Undefined relations between attributes (see CompareAttr) are considered to be disjoint, except when source attribute matches target attribute byte-by-byte.

func StripSlashes

func StripSlashes(s string) string

StripSlashes removes escaping of punctuation characters from attribute value

func WFNize

func WFNize(s string) (string, error)

WFNize transforms a string into CPE23-NAME compliant avstring value. This function isn't a part of standard. Quoted wildcards (*?) become unquoted ones (i.e. act as wildcards, not a literal '*' and '?') If wildcards are used, it is a responsibility of the user to make sure they comply with the standard, i.e. only appear at the beginning or at the end of the string and, in case of asterisk, only once in each case. Uppercase letters are valid avstring characters, but they are rarely (if ever) used in WFNs. It is recommended to strings.ToLower() the string before passing it to this function.

Types

type Attributes

type Attributes struct {
	Part      string
	Vendor    string
	Product   string
	Version   string
	Update    string
	Edition   string
	SWEdition string
	TargetSW  string
	TargetHW  string
	Other     string
	Language  string
}

Attributes defines the WFN Data Model Attributes.

func NewAttributesWithAny

func NewAttributesWithAny() *Attributes

NewAttributesWithAny allocates Attributes object with all fields initialized to Any logical value

func NewAttributesWithNA

func NewAttributesWithNA() *Attributes

NewAttributesWithNA allocates Attributes object with all fields initialized to NA logical value

func Parse

func Parse(s string) (*Attributes, error)

Parse parses Attributes from URI or formatted string binding.

func UnbindFmtString

func UnbindFmtString(s string) (*Attributes, error)

UnbindFmtString loads WFN from formatted string

func UnbindURI

func UnbindURI(s string) (*Attributes, error)

UnbindURI loads WFN from URI

func (Attributes) BindToFmtString

func (a Attributes) BindToFmtString() string

BindToFmtString binds WFN to formatted string

func (Attributes) BindToURI

func (a Attributes) BindToURI() string

BindToURI binds WFN to URI

func (*Attributes) Config

func (a *Attributes) Config() []*Attributes

Attrs is part of the Matcher interface

func (*Attributes) MatchOnlyVersion

func (a *Attributes) MatchOnlyVersion(attr *Attributes) bool

MatchOnlyVersion checks whether version matches

func (*Attributes) MatchWithoutVersion

func (a *Attributes) MatchWithoutVersion(attr *Attributes) bool

MatchWithoutVersion checks whether everything else besides the version matches

func (Attributes) String

func (a Attributes) String() string

String returns a string representation of the wfn

type Comparison

type Comparison struct {
	Part      Relation
	Vendor    Relation
	Product   Relation
	Version   Relation
	Update    Relation
	Edition   Relation
	Language  Relation
	SWEdition Relation
	TargetSW  Relation
	TargetHW  Relation
	Other     Relation
}

Comparison is the result of CPE name matching

func Compare

func Compare(src, tgt *Attributes) (Comparison, error)

Compare performs comparison of each attribute-value (A-V) of the wfns as per Name Matching Specification v.2.3 and returns the set relation between source and target attribute-values. The table below illustrates a set of source and target A-Vs and the resulting set of attribute comparison relations. +--------------------------------------------+------------------------------------+ | Attribute Relation Set | Name Comparison Relation | +--------------------------------------------+------------------------------------+ | any attribute relation is != | CPE name relation is DISJOINT (!=) | | all attribute relations are == | CPE name relation is EQAL (==) | | all attribute relations are Subset or == | CPE name relation is Subset | | all attribute relations are Superset or == | CPE name relation is Superset | +--------------------------------------------+------------------------------------+

func (Comparison) IsDisjoint

func (c Comparison) IsDisjoint() bool

IsDisjoint returns true if the result CPE name matching is disjoint

func (Comparison) IsEqual

func (c Comparison) IsEqual() bool

IsEqual returns true if the result CPE name matching is equal

func (Comparison) IsSubset

func (c Comparison) IsSubset() bool

IsSubset returns true if the result CPE name matching is a subset relation

func (Comparison) IsSuperset

func (c Comparison) IsSuperset() bool

IsSuperset returns true if the result CPE name matching is a superset relation

func (Comparison) Relation

func (c Comparison) Relation() Relation

Relation returns relation between matched CPE names

type Matcher

type Matcher interface {
	// Match returns attributes which match it
	// if require version, then Matcher which matches all versions should return false
	Match(attrs []*Attributes, requireVersion bool) (matches []*Attributes)
	// Config returns all attributes that are used by in the matching process
	Config() []*Attributes
}

Matcher knows whether it matches some attributes

func DontMatch

func DontMatch(m Matcher) Matcher

DontMatch returns a Matcher which matches if the given matchers doesn't

func MatchAll

func MatchAll(ms ...Matcher) Matcher

MatchAll returns a Matcher which matches only if all matchers match

func MatchAny

func MatchAny(ms ...Matcher) Matcher

MatchAll returns a Matcher which matches if any of the matchers match

type Relation

type Relation int

Relation describes four possible set relations of wfns attribute-value

const (
	Disjoint Relation = iota
	Subset
	Equal
	Superset
)

Possible values of Relation type

func CompareAttr

func CompareAttr(src, tgt string) (Relation, error)

CompareAttr calculates a relation between a pair of wfn attribute values. Accordingly to standard, string matching must be insensitive to lexical case, target A-V must not have wildcards. The table below defines possible set relations for each comparison ANY and NA are logical values as defined per [CPE23-N:5.3.1] i and k are wildcard-free attribute-value strings that are not identical, e.g. i is "foo" and k is "bar" m + w is attribute-value string containing a legal combination of unquoted question mark or asterisk wildcards

    at the beginning and/or the end of the string, e.g. "*b??"
Enumeration of
Attribute Comparison Set Relations

+------------+------------+--------------+ | Source A-V | Target A-V | Relation | +------------+------------+--------------+ | ANY | ANY | == | | ANY | NA | Superset | | ANY | i | Superset | | ANY | m + w | undef | | NA | ANY | Subset | | NA | NA | == | | NA | i | != | | NA | m + w | undefined | | i | i | == | | i | k | != | | i | m + w | undefined | | i | NA | != | | i | ANY | Subset | | m1 + w | m2 | Subset or != | | m + w | ANY | Subset | | m1 + w | NA | != | | m1 + w | m2 + w | undefined | +----------------------------------------+

func (Relation) String

func (r Relation) String() string

String return human readable representation of Relation value

Jump to

Keyboard shortcuts

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