forked from JesseCoretta/go-schemax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mu.go
1009 lines (839 loc) · 24.3 KB
/
mu.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package schemax
/*
NewMatchingRuleUses initializes a new [MatchingRuleUses] instance.
*/
func NewMatchingRuleUses() MatchingRuleUses {
r := MatchingRuleUses(newCollection(`matchingRuleUses`))
r.cast().SetPushPolicy(r.canPush)
return r
}
/*
NewMatchingRuleUse initializes and returns a new instance of [MatchingRuleUse],
ready for manual assembly. This method need not be used when creating
new [MatchingRuleUse] instances by way of parsing, as that is handled on an
internal basis.
Use of this method does NOT automatically push the return instance into
the [Schema.MatchingRuleUses] stack; this is left to the user.
Unlike the package-level [NewMatchingRuleUse] function, this method will
automatically reference its originating [Schema] instance (the receiver).
This negates the need for manual use of the [MatchingRuleUse.SetSchema]
method.
This is the recommended means of creating a new [MatchingRuleUse] instance
wherever a single [Schema] is being used, which represents most use cases.
*/
func (r Schema) NewMatchingRuleUse() MatchingRuleUse {
return NewMatchingRuleUse().SetSchema(r)
}
/*
NewMatchingRuleUse initializes and returns a new instance of [MatchingRuleUse],
ready for manual assembly. This method need not be used when creating
new [MatchingRuleUse] instances by way of parsing, as that is handled on an
internal basis.
Use of this function does not automatically reference the "parent" [Schema]
instance, leaving it up to the user to invoke the [MatchingRuleUse.SetSchema]
method manually.
When interacting with a single [Schema] instance, which represents most use
cases, use of the [Schema.NewMatchingRuleUse] method is PREFERRED over use of
this package-level function.
However certain migration efforts, schema audits and other such activities
may require distinct associations of [MatchingRuleUse] instances with specific
[Schema] instances. Use of this function allows the user to specify the
appropriate [Schema] instance at a later point for a specific instance of
an [MatchingRuleUse] instance.
*/
func NewMatchingRuleUse() MatchingRuleUse {
mu := MatchingRuleUse{newMatchingRuleUse()}
mu.matchingRuleUse.Extensions.setDefinition(mu)
return mu
}
func newMatchingRuleUse() *matchingRuleUse {
return &matchingRuleUse{
Name: NewName(),
Applies: NewAttributeTypeOIDList(`APPLIES`),
Extensions: NewExtensions(),
}
}
/*
Parse always returns an error, as parsing does not apply to [MatchingRuleUse]
instances, as they are meant to be dynamically generated -- not parsed.
See the [Schema.UpdateMatchingRuleUses] method for a means of refreshing
the current [Schema.MatchingRuleUses] stack based upon the [AttributeType]
instances present within the [Schema] instance at runtime.
*/
func (r MatchingRuleUse) Parse(raw string) error {
return mkerr("Parsing is not applicable to a MatchingRuleUse")
}
/*
Replace overrides the receiver with x. Both must bear an identical
numeric OID and x MUST be compliant.
Note that the relevant [Schema] instance must be configured to allow
definition override by way of the [AllowOverride] bit setting. See
the [Schema.Options] method for a means of accessing the settings
value.
Note that this method does not reallocate a new pointer instance
within the [MatchingRuleUse] envelope type, thus all references to the
receiver instance within various stacks will be preserved.
This is a fluent method.
*/
func (r MatchingRuleUse) Replace(x MatchingRuleUse) MatchingRuleUse {
if !r.Schema().Options().Positive(AllowOverride) {
return r
}
if !r.IsZero() && r.Compliant() {
r.matchingRuleUse.replace(x)
}
return r
}
func (r *matchingRuleUse) replace(x MatchingRuleUse) {
if r.OID.IsZero() {
return
} else if r.OID.NumericOID() != x.NumericOID() {
return
}
r.OID = x.matchingRuleUse.OID
r.Name = x.matchingRuleUse.Name
r.Desc = x.matchingRuleUse.Desc
r.Obsolete = x.matchingRuleUse.Obsolete
r.Applies = x.matchingRuleUse.Applies
r.Extensions = x.matchingRuleUse.Extensions
r.data = x.matchingRuleUse.data
r.schema = x.matchingRuleUse.schema
r.stringer = x.matchingRuleUse.stringer
r.data = x.matchingRuleUse.data
}
/*
Compliant returns a Boolean value indicative of every [MatchingRuleUse]
returning a compliant response from the [MatchingRuleUse.Compliant] method.
*/
func (r MatchingRuleUses) Compliant() bool {
var act int
for i := 0; i < r.Len(); i++ {
if r.Index(i).Compliant() {
act++
}
}
return act == r.Len()
}
/*
Compliant returns a Boolean value indicative of the receiver being fully
compliant per the required clauses of § 4.1.4 of RFC 4512:
- Numeric OID must be present and valid
- Numeric OID must correlate to a previously registered [MatchingRule]
*/
func (r MatchingRuleUse) Compliant() bool {
if r.IsZero() {
return false
}
var (
appl AttributeTypes = r.Applies()
act int // Applied AttributeType count
)
for i := 0; i < appl.Len(); i++ {
if appl.Index(i).Compliant() {
act++
}
}
if r.Schema().MatchingRules().get(r.NumericOID()).IsZero() {
return false
}
return act == r.Applies().Len()
}
/*
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
[MatchingRuleUse.Data] method.
This is a fluent method.
*/
func (r MatchingRuleUse) SetData(x any) MatchingRuleUse {
if !r.IsZero() {
r.matchingRuleUse.setData(x)
}
return r
}
func (r *matchingRuleUse) setData(x any) {
r.data = x
}
/*
Data returns the underlying value (x) assigned to the receiver's data storage field. Data
can be set within the receiver instance by way of the [MatchingRuleUse.SetData] method.
*/
func (r MatchingRuleUse) Data() (x any) {
if !r.IsZero() {
x = r.matchingRuleUse.data
}
return
}
/*
SetStringer allows the assignment of an individual [Stringer] function or
method to all [MatchingRuleUse] slices within the receiver stack instance.
Input of zero (0) variadic values, or an explicit nil, will overwrite all
preexisting stringer functions with the internal closure default, which is
based upon a one-time use of the [text/template] package by all receiver
slice instances.
Input of a non-nil closure function value will overwrite all preexisting
stringers.
This is a fluent method and may be used multiple times.
*/
func (r MatchingRuleUses) SetStringer(function ...Stringer) MatchingRuleUses {
for i := 0; i < r.Len(); i++ {
def := r.Index(i)
def.SetStringer(function...)
}
return r
}
/*
SetStringer allows the assignment of an individual [Stringer] function
or method to the receiver instance.
Input of zero (0) variadic values, or an explicit nil, will overwrite any
preexisting stringer function with the internal closure default, which is
based upon a one-time use of the [text/template] package by the receiver
instance.
Input of a non-nil closure function value will overwrite any preexisting
stringer.
This is a fluent method and may be used multiple times.
*/
func (r MatchingRuleUse) SetStringer(function ...Stringer) MatchingRuleUse {
if r.Compliant() {
r.matchingRuleUse.setStringer(function...)
}
return r
}
func (r *matchingRuleUse) setStringer(function ...Stringer) {
var stringer Stringer
if len(function) > 0 {
stringer = function[0]
}
if stringer == nil {
// no user provided closure means we
// defer to a general use stringer.
str, err := r.prepareString() // perform one-time text/template op
if err == nil {
// Save the stringer
r.stringer = func() string {
// Return a preserved value.
return str
}
}
return
}
// assign user-provided closure
r.stringer = stringer
}
/*
String is a stringer method that returns the string representation of
the receiver instance. A zero-value indicates an invalid receiver, or
that the [ObjectClass.SetStringer] method was not used during MANUAL
composition of the receiver.
*/
func (r MatchingRuleUse) String() (def string) {
if !r.IsZero() {
if r.matchingRuleUse.stringer != nil {
def = r.matchingRuleUse.stringer()
}
}
return
}
/*
Obsolete returns a Boolean value indicative of definition obsolescence.
*/
func (r MatchingRuleUse) Obsolete() (o bool) {
if !r.IsZero() {
o = r.matchingRuleUse.Obsolete
}
return
}
/*
SetObsolete sets the receiver instance to OBSOLETE if not already set.
Obsolescence cannot be unset.
This is a fluent method.
*/
func (r MatchingRuleUse) SetObsolete() MatchingRuleUse {
if !r.IsZero() {
r.matchingRuleUse.setObsolete()
}
return r
}
func (r *matchingRuleUse) setObsolete() {
if !r.Obsolete {
r.Obsolete = true
}
}
/*
Applies returns an [AttributeTypes] instance containing pointer references
to all [AttributeType] instances to which the receiver applies.
*/
func (r MatchingRuleUse) Applies() (aa AttributeTypes) {
if !r.IsZero() {
aa = r.matchingRuleUse.Applies
}
return
}
/*
SetApplies assigns the provided input values as applied [AttributeType]
instances advertised through the receiver instance.
This is a fluent method.
*/
func (r MatchingRuleUse) SetApplies(m ...any) MatchingRuleUse {
if !r.IsZero() {
r.matchingRuleUse.setApplies(m...)
}
return r
}
func (r *matchingRuleUse) setApplies(m ...any) {
var err error
for i := 0; i < len(m) && err == nil; i++ {
var at AttributeType
switch tv := m[i].(type) {
case string:
at = r.schema.AttributeTypes().get(tv)
case AttributeType:
at = tv
default:
err = ErrInvalidInput
}
if err == nil && at.Compliant() {
r.Applies.Push(at)
}
}
}
/*
SetSchema assigns an instance of [Schema] to the receiver instance. This allows
internal verification of certain actions without the need for user input of
an instance of [Schema] manually at each juncture.
Note that the underlying [Schema] instance is automatically set when creating
instances of this type by way of parsing, as well as if the receiver instance
was initialized using the [Schema.NewMatchingRuleUse] method.
This is a fluent method.
*/
func (r MatchingRuleUse) SetSchema(schema Schema) MatchingRuleUse {
if !r.IsZero() {
r.matchingRuleUse.setSchema(schema)
}
return r
}
func (r *matchingRuleUse) setSchema(schema Schema) {
r.schema = schema
}
/*
Schema returns the [Schema] instance associated with the receiver instance.
*/
func (r MatchingRuleUse) Schema() (s Schema) {
if !r.IsZero() {
s = r.matchingRuleUse.getSchema()
}
return
}
func (r *matchingRuleUse) getSchema() (s Schema) {
if r != nil {
s = r.schema
}
return
}
/*
IsIdentifiedAs returns a Boolean value indicative of whether id matches
either the numericOID or descriptor of the receiver instance. Case is
not significant in the matching process.
*/
func (r MatchingRuleUse) IsIdentifiedAs(id string) (ident bool) {
if !r.IsZero() {
ident = id == r.NumericOID() || r.matchingRuleUse.Name.contains(id)
}
return
}
/*
MatchingRuleUses returns the [MatchingRuleUses] instance from
within the receiver instance.
*/
func (r Schema) MatchingRuleUses() (mus MatchingRuleUses) {
slice, _ := r.cast().Index(matchingRuleUsesIndex)
mus, _ = slice.(MatchingRuleUses)
return
}
/*
prepareString returns a string an an error indicative of an attempt
to represent the receiver instance as a string using [text/template].
*/
func (r *matchingRuleUse) prepareString() (str string, err error) {
buf := newBuf()
t := newTemplate(r.Type()).
Funcs(funcMap(map[string]any{
`MatchingRuleOID`: r.OID.NumericOID,
`ExtensionSet`: r.Extensions.tmplFunc,
`Applied`: r.Applies.String,
`Obsolete`: func() bool { return r.Obsolete },
}))
if t, err = t.Parse(matchingRuleUseTmpl); err == nil {
if err = t.Execute(buf, struct {
Definition *matchingRuleUse
HIndent string
}{
Definition: r,
HIndent: hindent(r.schema.Options().Positive(HangingIndents)),
}); err == nil {
str = buf.String()
}
}
return
}
/*
Maps returns slices of [DefinitionMap] instances.
*/
func (r MatchingRuleUses) Maps() (defs DefinitionMaps) {
defs = make(DefinitionMaps, r.Len())
for i := 0; i < r.Len(); i++ {
defs[i] = r.Index(i).Map()
}
return
}
/*
Map marshals the receiver instance into an instance of
[DefinitionMap].
*/
func (r MatchingRuleUse) Map() (def DefinitionMap) {
if r.IsZero() {
return
}
var applies []string
for i := 0; i < r.Applies().Len(); i++ {
m := r.Applies().Index(i)
applies = append(applies, m.OID())
}
def = make(DefinitionMap, 0)
def[`NUMERICOID`] = []string{r.NumericOID()}
def[`NAME`] = r.Names().List()
def[`DESC`] = []string{r.Description()}
def[`OBSOLETE`] = []string{bool2str(r.Obsolete())}
def[`APPLIES`] = applies
def[`RAW`] = []string{r.String()}
// copy our extensions from receiver r
// into destination def.
def = mapTransferExtensions(r, def)
// Clean up any empty fields
def.clean()
return
}
/*
Inventory returns an instance of [Inventory] which represents the current
inventory of [MatchingRuleUse] instances within the receiver.
The keys are numeric OIDs, while the values are zero (0) or more string
slices, each representing a name by which the definition is known.
*/
func (r MatchingRuleUses) Inventory() (inv Inventory) {
inv = make(Inventory, 0)
for i := 0; i < r.len(); i++ {
def := r.index(i)
inv[def.NumericOID()] = def.Names().List()
}
return
}
/*
Type returns the string literal "matchingRuleUse".
*/
func (r MatchingRuleUse) Type() string {
return r.matchingRuleUse.Type()
}
func (r matchingRuleUse) Type() string {
return `matchingRuleUse`
}
/*
Type returns the string literal "matchingRuleUses".
*/
func (r MatchingRuleUses) Type() string {
return `matchingRuleUses`
}
func (r MatchingRuleUses) prepareStrings() (err error) {
for i := 0; i < r.Len() && err == nil; i++ {
mu := r.index(i)
var str string
str, err = mu.matchingRuleUse.prepareString()
if err == nil {
mu.matchingRuleUse.stringer = func() string {
return str
}
}
}
return
}
/*
OID returns the string representation of an OID -- which is either
a numeric OID or descriptor -- that refers to the [MatchingRule]
upon which the receiver instance is based.
*/
func (r MatchingRuleUse) OID() (oid string) {
if !r.IsZero() {
oid = r.NumericOID() // default
if r.matchingRuleUse.Name.len() > 0 {
oid = r.matchingRuleUse.Name.index(0)
}
}
return
}
/*
Extensions returns the [Extensions] instance -- if set -- within
the receiver.
*/
func (r MatchingRuleUse) Extensions() (e Extensions) {
if !r.IsZero() {
e = r.matchingRuleUse.Extensions
}
return
}
/*
SetExtension assigns key x to value xstrs within the receiver's underlying
[Extensions] instance.
This is a fluent method.
*/
func (r MatchingRuleUse) SetExtension(x string, xstrs ...string) MatchingRuleUse {
if !r.IsZero() {
r.matchingRuleUse.setExtension(x, xstrs...)
}
return r
}
func (r *matchingRuleUse) setExtension(x string, xstrs ...string) {
r.Extensions.Set(x, xstrs...)
}
/*
NumericOID returns the string representation of the numeric OID
held by the receiver instance.
*/
func (r MatchingRuleUse) NumericOID() (noid string) {
if !r.IsZero() {
noid = r.matchingRuleUse.OID.NumericOID()
}
return
}
/*
SetNumericOID allows the manual assignment of a numeric OID to the
receiver instance if the following are all true:
- The input id value is a syntactically valid numeric OID
- The input id relates to a known [MatchingRule] instance within the associated [Schema]
- The receiver does not already possess a numeric OID
This is a fluent method.
*/
func (r MatchingRuleUse) SetNumericOID(id string) MatchingRuleUse {
if !r.IsZero() {
r.matchingRuleUse.setNumericOID(id)
}
return r
}
func (r *matchingRuleUse) setNumericOID(id string) {
mr := r.schema.MatchingRules().Get(id)
// only set an OID when the receiver
// lacks one (iow: no modifications)
// and when the MR has been found.
if !mr.IsZero() && r.OID.IsZero() {
r.OID = mr
}
return
}
/*
Name returns the string form of the principal name of the receiver instance, if set.
*/
func (r MatchingRuleUse) Name() (id string) {
if !r.IsZero() {
id = r.matchingRuleUse.Name.index(0)
}
return
}
/*
Names returns the underlying instance of [QuotedDescriptorList] from
within the receiver.
*/
func (r MatchingRuleUse) Names() (names QuotedDescriptorList) {
if !r.IsZero() {
names = r.matchingRuleUse.Name
}
return
}
/*
SetName assigns the provided names to the receiver instance.
Name instances must conform to RFC 4512 descriptor format but
need not be quoted.
This is a fluent method.
*/
func (r MatchingRuleUse) SetName(x ...string) MatchingRuleUse {
if !r.IsZero() {
r.matchingRuleUse.setName(x...)
}
return r
}
func (r *matchingRuleUse) setName(x ...string) {
for i := 0; i < len(x); i++ {
r.Name.Push(x[i])
}
}
/*
Description returns the underlying (optional) descriptive text
assigned to the receiver instance.
*/
func (r MatchingRuleUse) Description() (desc string) {
if !r.IsZero() {
desc = r.matchingRuleUse.Desc
}
return
}
/*
SetDescription parses desc into the underlying DESC clause within the
receiver instance. Although a RFC 4512-compliant QuotedString is
required, the outer single-quotes need not be specified literally.
*/
func (r MatchingRuleUse) SetDescription(desc string) MatchingRuleUse {
if !r.IsZero() {
r.matchingRuleUse.setDescription(desc)
}
return r
}
func (r *matchingRuleUse) setDescription(desc string) {
if len(desc) < 3 {
return
}
if rune(desc[0]) == rune(39) {
desc = desc[1:]
}
if rune(desc[len(desc)-1]) == rune(39) {
desc = desc[:len(desc)-1]
}
r.Desc = desc
return
}
/*
IsZero returns a Boolean value indicative of a nil receiver state.
*/
func (r MatchingRuleUse) IsZero() bool {
return r.matchingRuleUse == nil
}
func (r MatchingRuleUses) canPush(x ...any) (err error) {
if len(x) == 0 {
return
}
for i := 0; i < len(x) && err == nil; i++ {
mu, ok := x[i].(MatchingRuleUse)
if !ok || mu.IsZero() {
err = ErrTypeAssert
} else if tst := r.get(mu.NumericOID()); !tst.IsZero() {
err = mkerr(ErrNotUnique.Error() + ": " + mu.Type() + `, ` + mu.NumericOID())
}
}
return
}
/*
Len returns the current integer length of the receiver instance.
*/
func (r MatchingRuleUses) Len() int {
return r.len()
}
func (r MatchingRuleUses) len() int {
return r.cast().Len()
}
/*
String is a stringer method that returns the string representation
of the receiver instance.
*/
func (r MatchingRuleUses) String() string {
return r.cast().String()
}
/*
IsZero returns a Boolean value indicative of a nil receiver state.
*/
func (r MatchingRuleUses) IsZero() bool {
return r.cast().IsZero()
}
/*
Index returns the instance of [MatchingRuleUse] found within the
receiver stack instance at index N. If no instance is found at
the index specified, a zero [MatchingRuleUse] instance is returned.
*/
func (r MatchingRuleUses) Index(idx int) MatchingRuleUse {
return r.index(idx)
}
func (r MatchingRuleUses) index(idx int) (mu MatchingRuleUse) {
slice, found := r.cast().Index(idx)
if found {
if _mu, ok := slice.(MatchingRuleUse); ok {
mu = _mu
}
}
return
}
/*
Push returns an error following an attempt to push a [MatchingRuleUse]
instance into the receiver instance.
*/
func (r MatchingRuleUses) Push(mu any) error {
return r.push(mu)
}
func (r MatchingRuleUses) push(x any) (err error) {
switch tv := x.(type) {
case MatchingRuleUse:
if tv.IsZero() {
err = ErrDefNonCompliant
break
}
r.cast().Push(tv)
default:
err = ErrInvalidType
}
return
}
/*
Contains calls [MatchingRuleUses.Get] to return a Boolean value indicative of
a successful, non-zero retrieval of an [MatchingRuleUse] instance -- matching
the provided id -- from within the receiver stack instance.
*/
func (r MatchingRuleUses) Contains(id string) bool {
return r.contains(id)
}
func (r MatchingRuleUses) contains(id string) bool {
return !r.get(id).IsZero()
}
/*
Get returns an instance of [MatchingRuleUse] based upon a search for id within
the receiver stack instance.
The return instance, if not nil, was retrieved based upon a textual match of
the principal identifier of an [MatchingRuleUse] and the provided id.
The return instance is nil if no match was made.
Case is not significant in the matching process.
*/
func (r MatchingRuleUses) Get(id string) MatchingRuleUse {
return r.get(id)
}
func (r MatchingRuleUses) get(id string) (mu MatchingRuleUse) {
for i := 0; i < r.len() && mu.IsZero(); i++ {
if _mu := r.index(i); !_mu.IsZero() {
if _mu.IsIdentifiedAs(id) {
mu = _mu
}
}
}
return
}
/*
makeMatchingRuleUse fashions and returns a new MatchingRuleUse instance
based on the contents of the receiver instance. The returned instance,
assuming a nil error condition, may have its APPLIES clause populated
with "users" (AttributeType instances) of the indicated matchingRule.
*/
func (r MatchingRule) makeMatchingRuleUse() (mu MatchingRuleUse, err error) {
if !r.Compliant() {
err = ErrDefNonCompliant
return
}
_mu := newMatchingRuleUse()
_mu.Name = r.matchingRule.Name
_mu.OID = r
_mu.schema = r.Schema()
_mu.Extensions = r.matchingRule.Extensions
mu = MatchingRuleUse{_mu}
mu.SetStringer()
return
}
/*
updateMatchingRuleUses returns an instance of error following an attempt
to refresh the collection of MatchingRuleUse instances within the
receiver to include input variable "at" wherever appropriate.
*/
func (r Schema) updateMatchingRuleUses(ats AttributeTypes) (err error) {
if ats.len() == 0 {
return
}
for i := 0; i < ats.len() && err == nil; i++ {
if at := ats.index(i); !at.IsZero() {
for _, funk := range []func(AttributeType) error{
r.updateEqualityUses,
r.updateSubstringUses,
r.updateOrderingUses,
} {
if err = funk(at); err != nil {
break
}
}
}
}
if err == nil {
err = r.MatchingRuleUses().prepareStrings()
}
return
}
// updateEqualityUses is called by updateMatchingRuleUses and will
// extract any equality matchingRule details from the input instance
// of AttributeType and store information about this association in
// the receiver's MU stack field. An error is returned should any
// part of this process fail.
func (r Schema) updateEqualityUses(at AttributeType) (err error) {
if eqty := at.Equality(); !eqty.IsZero() {
mu := r.MatchingRuleUses().get(eqty.NumericOID())
// If the MatchingRuleUse instance does not exist,
// create it now.
if mu.IsZero() {
_eqy := r.MatchingRules().get(eqty.NumericOID())
if _eqy.IsZero() {
err = ErrEqualityRuleNotFound
} else if mu, err = _eqy.makeMatchingRuleUse(); err == nil {
r.MatchingRuleUses().push(mu)
}
}
// Append the AttributeType instance to the
// MatchingRuleUse.Applies stack, assuming
// no errors occur.
if err == nil {
mu.setApplies(at)
}
}
return
}
// updateSubstringUses is called by updateMatchingRuleUses and will
// extract any substring matchingRule details from the input instance
// of AttributeType and store information about this association in
// the receiver's MU stack field. An error is returned should any
// part of this process fail.
func (r Schema) updateSubstringUses(at AttributeType) (err error) {
if substr := at.Substring(); !substr.IsZero() {
mu := r.MatchingRuleUses().get(substr.NumericOID())
// If the MatchingRuleUse instance does not exist,
// create it now.
if mu.IsZero() {
_substr := r.MatchingRules().get(substr.NumericOID())
if _substr.IsZero() {
err = ErrSubstringRuleNotFound
} else if mu, err = _substr.makeMatchingRuleUse(); err == nil {
r.MatchingRuleUses().push(mu)
}
}
// Append the AttributeType instance to the
// MatchingRuleUse.Applies stack, assuming
// no errors occur.
if err == nil {
mu.setApplies(at)
}
}
return
}
// updateOrderingUses is called by updateMatchingRuleUses and will
// extract any ordering matchingRule details from the input instance
// of AttributeType and store information about this association in
// the receiver's MU stack field. An error is returned should any
// part of this process fail.
func (r Schema) updateOrderingUses(at AttributeType) (err error) {
if order := at.Ordering(); !order.IsZero() {
mu := r.MatchingRuleUses().get(order.NumericOID())
// If the MatchingRuleUse instance does not exist,
// create it now.
if mu.IsZero() {
_order := r.MatchingRules().get(order.NumericOID())
if _order.IsZero() {
err = ErrOrderingRuleNotFound
} else if mu, err = _order.makeMatchingRuleUse(); err == nil {
r.MatchingRuleUses().push(mu)
}
}
// Append the AttributeType instance to the
// MatchingRuleUse.Applies stack, assuming
// no errors occur.
if err == nil {