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 ¶
const ( Any = "" NA = "-" )
Possible logical value of Attributes empty string considered ANY when parsing and unquoted "-" is illegal in WFN attribute-value
Variables ¶
var KnownParts = map[string]string{
"a": "application",
"o": "operating system",
"h": "hardware",
}
KnownParts is a map of known WFN attribute parts.
Functions ¶
func HasWildcard ¶
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 ¶
StripSlashes removes escaping of punctuation characters from attribute value
func WFNize ¶
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 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 (Attributes) BindToFmtString ¶
func (a Attributes) BindToFmtString() string
BindToFmtString binds WFN to formatted string
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 Relation ¶
type Relation int
Relation describes four possible set relations of wfns attribute-value
func CompareAttr ¶
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 | +----------------------------------------+