From 0928df7ec9bafd57282e84cd0a52b8b9bceb5a30 Mon Sep 17 00:00:00 2001 From: Jesse Coretta <{ID}+{username}@users.noreply.github.com> Date: Tue, 5 Nov 2024 22:18:20 -0800 Subject: [PATCH] new features, adjust AttributeType.SetObsolete --- at.go | 14 ++++++++------ dc.go | 2 ++ dc_test.go | 1 + ds.go | 14 ++++++++++++++ ds_test.go | 25 +++++++++++++++++++++++++ nf.go | 21 +++++++++++++++++++++ nf_test.go | 3 +++ oc.go | 22 ++++++++++++++++++++++ oc_test.go | 2 ++ 9 files changed, 98 insertions(+), 6 deletions(-) diff --git a/at.go b/at.go index 2588c65..3cdf96f 100644 --- a/at.go +++ b/at.go @@ -1479,11 +1479,7 @@ func (r AttributeType) SetNoUserModification(x any) AttributeType { } /* -SetObsolete assigns the input value to the underlying OBSOLETE clause within -the receiver. - -Input types may be bool, or string representations of bool. When strings -are used, case is not significant. +SetObsolete sets the receiver's obsolescence state to true. Obsolescence cannot be unset. @@ -1491,12 +1487,18 @@ This is a fluent method. */ func (r AttributeType) SetObsolete(x any) AttributeType { if !r.IsZero() { - r.attributeType.setBoolean(`obs`, x) + r.attributeType.setObsolete() } return r } +func (r *attributeType) setObsolete() { + if !r.Obsolete { + r.Obsolete = true + } +} + func (r *attributeType) setBoolean(t string, x any) { var Bool bool diff --git a/dc.go b/dc.go index a1a50c3..27f17a9 100644 --- a/dc.go +++ b/dc.go @@ -445,6 +445,8 @@ func (r DITContentRules) Compliant() bool { /* StructuralClass returns the STRUCTURAL [ObjectClass] set within the receiver instance, or a zero instance if unset. + +This method is essentially the inverse of [ObjectClass.EnforcedBy]. */ func (r DITContentRule) StructuralClass() (soc ObjectClass) { if !r.IsZero() { diff --git a/dc_test.go b/dc_test.go index cdc3ded..85ce351 100644 --- a/dc_test.go +++ b/dc_test.go @@ -353,6 +353,7 @@ func TestDITContentRule_codecov(t *testing.T) { t.Errorf("%s failed: expected success, got %v", t.Name(), err) return } + def.StructuralClass().EnforcedBy() _ = def.macro() def.setOID(`2.5.6.2`) diff --git a/ds.go b/ds.go index 6e6111b..b918981 100644 --- a/ds.go +++ b/ds.go @@ -96,6 +96,20 @@ func (r *dITStructureRule) replace(x DITStructureRule) { r.data = x.dITStructureRule.data } +/* +NamedObjectClass returns the "namedObjectClass" of the receiver instance. + +The "namedObjectClass" describes the STRUCTURAL [ObjectClass] specified +in the receiver's [NameForm] instance, and is described in [ITU-T Rec. +X.501 clause 13.7.5]. + +[ITU-T Rec. X.501 clause 13.7.5]: https://www.itu.int/rec/T-REC-X.501 +*/ +func (r DITStructureRule) NamedObjectClass() (noc ObjectClass) { + noc = r.Form().OC() + return +} + /* SetData assigns x to the receiver instance. This is a general-use method and has no specific intent beyond convenience. The contents may be subsequently accessed via the diff --git a/ds_test.go b/ds_test.go index e47747b..873d453 100644 --- a/ds_test.go +++ b/ds_test.go @@ -5,6 +5,13 @@ import ( "testing" ) +/* +This example demonstrates an analysis of a distinguished name to determine +whether it honors the receiver instance of [DITStructureRule]. + +Note: this example assumes a legitimate schema variable is defined +in place of the fictional "mySchema" var shown here for simplicity. +*/ func ExampleDITStructureRule_Govern() { dn := `dc=example,dc=com` // flattened context (1 comma) @@ -23,6 +30,9 @@ func ExampleDITStructureRule_Govern() { /* This example demonstrates the creation of a [DITStructureRule]. + +Note: this example assumes a legitimate schema variable is defined +in place of the fictional "mySchema" var shown here for simplicity. */ func ExampleNewDITStructureRule() { // First create a name form that requires an @@ -53,6 +63,21 @@ func ExampleNewDITStructureRule() { // FORM fictionalPersonForm ) } +/* +This example demonstrates the means of accessing the STRUCTURAL [ObjectClass] +instance held by the [NameForm] instance assigned to the [DITStructureRule] +instance. + +Note: this example assumes a legitimate schema variable is defined +in place of the fictional "mySchema" var shown here for simplicity. +*/ +func ExampleDITStructureRule_NamedObjectClass() { + ds := mySchema.DITStructureRules().Get(1) // Integer Identifier #1 + noc := ds.NamedObjectClass() + fmt.Println(noc.OID()) + // Output: uddiBusinessEntity +} + /* This example demonstrates a compliancy check of a [DITStructureRule] instance. diff --git a/nf.go b/nf.go index d9ed0f0..540dd83 100644 --- a/nf.go +++ b/nf.go @@ -189,6 +189,27 @@ func (r *nameForm) replace(x NameForm) { r.data = x.nameForm.data } +/* +EnforcedBy returns an instance of [DITStructureRules] containing all +[DITStructureRule] instances which enforce the receiver instance. A +return value with an integer length of zero (0) indicates that there +are no [DITStructureRule] instances which bear the receiver instance +through the 'FORM' clause at present. +*/ +func (r NameForm) EnforcedBy() (dsr DITStructureRules) { + if !r.Schema().IsZero() { + dsr = NewDITStructureRules() + rules := r.Schema().DITStructureRules() + for i := 0; i < rules.Len(); i++ { + if ds := rules.Index(i); ds.Form().IsIdentifiedAs(r.OID()) { + dsr.Push(ds) + } + } + } + + return +} + /* IsIdentifiedAs returns a Boolean value indicative of whether id matches either the numericOID or descriptor of the receiver instance. Case is diff --git a/nf_test.go b/nf_test.go index 56474c0..317855a 100644 --- a/nf_test.go +++ b/nf_test.go @@ -347,6 +347,7 @@ func TestNameForm_codecov(t *testing.T) { _ = def.Name() _ = def.Names() _ = def.Extensions() + _ = def.EnforcedBy() _ = def.Must() _ = def.May() _ = def.Schema() @@ -395,6 +396,8 @@ func TestNameForm_codecov(t *testing.T) { t.Errorf("%s failed: expected success, got %v", t.Name(), err) return } + def.EnforcedBy() + _ = def.macro() def.setOID(`2.5.13.2`) diff --git a/oc.go b/oc.go index 76ed77b..5495cf4 100644 --- a/oc.go +++ b/oc.go @@ -146,6 +146,28 @@ func (r ObjectClass) macro() (m []string) { return } +/* +EnforcedBy returns the [DITContentRule] instance which bears the same +numeric OID held by the receiver instance, which must be a STRUCTURAL +[ObjectClass]. + +This method is essentially the inverse of [DITContentRule.StructuralClass]. + +A schema can only contain one (1) such [DITContentRule] per STRUCTURAL +[ObjectClass]. + +If the return instance is zero, this means that either the receiver is +not a STRUCTURAL [ObjectClass], or that no [DITContentRule] bearing the +receiver's numeric OID is currently in force. +*/ +func (r ObjectClass) EnforcedBy() (dcr DITContentRule) { + if !r.Schema().IsZero() && r.Kind() == StructuralKind { + dcr = r.Schema().DITContentRules().Get(r.NumericOID()) + } + + return +} + /* SetName assigns the provided names to the receiver instance. diff --git a/oc_test.go b/oc_test.go index ac0b0b8..2470f52 100644 --- a/oc_test.go +++ b/oc_test.go @@ -440,6 +440,7 @@ func TestObjectClass_codecov(t *testing.T) { bmr.cast().Push(NewObjectClass().SetSchema(mySchema)) bmr.cast().Push(NewObjectClass().SetSchema(mySchema).SetNumericOID(`1.2.3.4.5`)) var bad ObjectClass + bad.EnforcedBy() bmr.cast().Push(bad) ObjectClasses(bmr.cast()).oIDsStringerPretty(0) @@ -530,6 +531,7 @@ func TestObjectClass_codecov(t *testing.T) { def.SetMust(rune(11)) def.SetMay(mySchema.AttributeTypes().Get(`cn`)) def.SetMay(rune(11)) + def.EnforcedBy() def.SetSuperClass(mySchema.ObjectClasses().Get(`top`)) def.SetSuperClass(rune(11)) def.SetSuperClass(ObjectClass{})