This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
oc.go
1952 lines (1627 loc) · 43.3 KB
/
oc.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
/*
NewObjectClass initializes and returns a new instance of [ObjectClass],
ready for manual assembly. This method need not be used when creating
new [ObjectClass] 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.ObjectClasses] stack; this is left to the user.
Unlike the package-level [NewObjectClass] function, this method will
automatically reference its originating [Schema] instance (the receiver).
This negates the need for manual use of the [ObjectClass.SetSchema]
method.
This is the recommended means of creating a new [ObjectClass] instance
wherever a single [Schema] is being used, which represents most use cases.
*/
func (r Schema) NewObjectClass() ObjectClass {
return NewObjectClass().SetSchema(r)
}
/*
NewObjectClasses initializes and returns a new [ObjectClasses] instance,
configured to allow the storage of all [ObjectClass] instances.
*/
func NewObjectClasses() ObjectClasses {
r := ObjectClasses(newCollection(``))
r.cast().SetPushPolicy(r.canPush)
return r
}
/*
NewObjectClassOIDList initializes and returns a new [ObjectClasses] that
has been configured to allow the storage of arbitrary [ObjectClass] instances.
*/
func NewObjectClassOIDList(label ...string) ObjectClasses {
name := `oc_oidlist`
if len(label) > 0 {
name = label[0]
}
r := ObjectClasses(newOIDList(name))
r.cast().
SetPushPolicy(r.canPush).
SetPresentationPolicy(r.oIDsStringer)
return r
}
/*
NewObjectClass initializes and returns a new instance of [ObjectClass],
ready for manual assembly. This method need not be used when creating
new [ObjectClass] 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 [ObjectClass.SetSchema]
method manually.
When interacting with a single [Schema] instance, which represents most use
cases, use of the [Schema.NewObjectClass] 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 [ObjectClass] 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 [ObjectClass] instance.
*/
func NewObjectClass() ObjectClass {
oc := ObjectClass{newObjectClass()}
oc.objectClass.Extensions.setDefinition(oc)
return oc
}
func newObjectClass() *objectClass {
return &objectClass{
Name: NewName(),
Must: NewAttributeTypeOIDList(`MUST`),
May: NewAttributeTypeOIDList(`MAY`),
SuperClasses: NewObjectClassOIDList(`SUP`),
Extensions: NewExtensions(),
}
}
/*
Marshal returns an error following an attempt to marshal the contents of
def, which may be either a [DefinitionMap] or map[string]any instance.
The receiver instance must be initialized prior to use of this method
using the [Schema.NewObjectClass] method.
*/
func (r ObjectClass) Marshal(def any) error {
m, err := getMarshalMap(r, def)
if err != nil {
return err
}
for k, v := range m {
switch key := uc(k); key {
case `NAME`:
switch tv := v.(type) {
case string:
r.SetName(tv)
case []string:
r.SetName(tv...)
}
case `DESC`, `NUMERICOID`:
z := map[string]func(string) ObjectClass{
`DESC`: r.SetDescription,
`NUMERICOID`: r.SetNumericOID,
}
switch tv := v.(type) {
case string:
z[k](tv)
case []string:
z[k](tv[0])
}
case `OBSOLETE`:
r.marshalBoolean(v)
case `KIND`:
r.marshalKind(v)
case `SUP`, `MUST`, `MAY`:
r.marshalMulti(key, v)
default:
r.marshalExt(key, v)
}
}
if !r.Compliant() {
return ErrDefNonCompliant
}
r.SetStringer()
return nil
}
func (r ObjectClass) marshalKind(v any) {
switch tv := v.(type) {
case string:
r.SetKind(tv)
case []string:
r.SetKind(tv[0])
}
}
func (r ObjectClass) marshalBoolean(v any) {
switch tv := v.(type) {
case string:
if eq(tv, `TRUE`) {
r.SetObsolete()
}
case []string:
if eq(tv[0], `TRUE`) {
r.SetObsolete()
}
case bool:
if tv {
r.SetObsolete()
}
}
}
func (r ObjectClass) marshalExt(key string, v any) {
if hasPfx(key, `X-`) {
switch tv := v.(type) {
case string:
r.SetExtension(key, tv)
case []string:
r.SetExtension(key, tv...)
}
}
}
func (r ObjectClass) marshalMulti(k string, v any) {
z := map[string]func(...any) ObjectClass{
`MUST`: r.SetMust,
`MAY`: r.SetMay,
`SUP`: r.SetSuperClass,
}
switch tv := v.(type) {
case []string:
for i := 0; i < len(tv); i++ {
z[k](tv[i])
}
case string:
z[k](tv)
}
}
/*
Parse returns an error following an attempt to parse raw into the receiver
instance.
Note that the receiver MUST possess a [Schema] reference prior to the execution
of this method.
Also note that successful execution of this method does NOT automatically push
the receiver into any [ObjectClass] stack, nor does it automatically execute
the [ObjectClass.SetStringer] method, leaving these tasks to the user. If the
automatic handling of these tasks is desired, see the [Schema.ParseObjectClass]
method as an alternative.
*/
func (r ObjectClass) Parse(raw string) (err error) {
if r.IsZero() {
err = ErrNilReceiver
return
}
if r.getSchema().IsZero() {
err = ErrNilSchemaRef
return
}
err = r.objectClass.parse(raw)
return
}
func (r *objectClass) parse(raw string) error {
// parseMR wraps the antlr4512 ObjectClass parser/lexer
mp, err := parseOC(raw)
if err == nil {
// We received the parsed data from ANTLR (mp).
// Now we need to marshal it into the receiver.
var def ObjectClass
if def, err = r.schema.marshalOC(mp); err == nil {
r.OID = def.NumericOID()
_r := ObjectClass{r}
_r.replace(def)
}
}
return err
}
func (r ObjectClass) setOID(x string) {
if !r.IsZero() {
r.objectClass.OID = x
}
}
func (r ObjectClass) macro() (m []string) {
if !r.IsZero() {
m = r.objectClass.Macro
}
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.
Name instances must conform to RFC 4512 descriptor format but
need not be quoted.
This is a fluent method.
*/
func (r ObjectClass) SetName(x ...string) ObjectClass {
if !r.IsZero() {
r.objectClass.setName(x...)
}
return r
}
func (r *objectClass) setName(x ...string) {
b4 := r.Name.Len()
for i := 0; i < len(x); i++ {
r.Name.Push(x[i])
}
if r.Name.Len()-len(x) != b4 {
r.err = ErrInvalidNames
}
}
/*
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
[ObjectClass.Data] method.
This is a fluent method.
*/
func (r ObjectClass) SetData(x any) ObjectClass {
if !r.IsZero() {
r.objectClass.setData(x)
}
return r
}
func (r *objectClass) 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 [ObjectClass.SetData] method.
*/
func (r ObjectClass) Data() (x any) {
if !r.IsZero() {
x = r.objectClass.data
}
return
}
/*
SetExtension assigns key x to value xstrs within the receiver's underlying
[Extensions] instance.
This is a fluent method.
*/
func (r ObjectClass) SetExtension(x string, xstrs ...string) ObjectClass {
if !r.IsZero() {
r.objectClass.setExtension(x, xstrs...)
}
return r
}
func (r *objectClass) setExtension(x string, xstrs ...string) {
r.Extensions.Set(x, xstrs...)
}
/*
SetKind assigns the abstraction of an objectClass "kind" to the receiver
instance. Valid input types are as follows:
- Literal uint consts ([AbstractKind], [AuxiliaryKind], [StructuralKind])
- int equivalents of uint consts
- string names of known objectClass kinds
In the case of string names, case is not significant.
This is a fluent method.
*/
func (r ObjectClass) SetKind(k any) ObjectClass {
if !r.IsZero() {
r.objectClass.setKind(k)
}
return r
}
func (r *objectClass) setKind(k any) {
switch tv := k.(type) {
case string:
switch lc(tv) {
case `structural`, ``:
r.Kind = StructuralKind
case `abstract`:
r.Kind = AbstractKind
case `auxiliary`:
r.Kind = AuxiliaryKind
}
case int:
if 0 <= tv && tv <= 2 {
r.Kind = uint(tv)
}
case uint:
switch tv {
case AbstractKind,
AuxiliaryKind,
StructuralKind:
r.Kind = tv
}
}
}
/*
SetMust assigns the provided input [AttributeType] instance(s) to the
receiver's MUST clause.
This is a fluent method.
*/
func (r ObjectClass) SetMust(m ...any) ObjectClass {
if !r.IsZero() {
r.objectClass.setMust(m...)
}
return r
}
func (r *objectClass) setMust(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 = ErrInvalidType
}
if err == nil && !at.IsZero() {
r.Must.Push(at)
}
}
if err != nil {
r.err = err
}
}
/*
SetMay assigns the provided input [AttributeType] instance(s) to the
receiver's MAY clause.
This is a fluent method.
*/
func (r ObjectClass) SetMay(m ...any) ObjectClass {
if !r.IsZero() {
r.objectClass.setMay(m...)
}
return r
}
func (r *objectClass) setMay(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 = ErrInvalidType
}
if err == nil && !at.IsZero() {
r.May.Push(at)
}
}
if err != nil {
r.err = err
}
}
/*
SetSuperClass appends the input value(s) to the the super classes stack within the
the receiver. Valid input types are string, to represent an RFC 4512 OID residing
in the underlying [Schema] instance, or an bonafide [ObjectClass] instance already
obtained or crafted.
This is a fluent method.
*/
func (r ObjectClass) SetSuperClass(x ...any) ObjectClass {
if !r.IsZero() {
r.objectClass.setSuperClass(x...)
}
return r
}
func (r *objectClass) setSuperClass(x ...any) {
var err error
for i := 0; i < len(x) && err == nil; i++ {
var sup ObjectClass
switch tv := x[i].(type) {
case string:
sup = r.schema.ObjectClasses().get(tv)
case ObjectClass:
sup = tv
default:
err = ErrInvalidType
continue
}
err = r.verifySuperClass(sup.objectClass)
if err == nil && !sup.IsZero() {
r.SuperClasses.push(sup)
}
}
if err != nil {
r.err = err
}
}
/*
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 [ObjectClass] envelope type, thus all references to the
receiver instance within various stacks will be preserved.
This is a fluent method.
*/
func (r ObjectClass) Replace(x ObjectClass) ObjectClass {
if !r.Schema().Options().Positive(AllowOverride) {
return r
}
if !r.IsZero() && x.Compliant() {
r.objectClass.replace(x)
}
return r
}
func (r *objectClass) replace(x ObjectClass) {
if r.OID == `` {
r.err = ErrMissingNumericOID
return
} else if r.OID != x.NumericOID() {
r.err = ErrInvalidOID
return
}
r.OID = x.objectClass.OID
r.Macro = x.objectClass.Macro
r.Name = x.objectClass.Name
r.Desc = x.objectClass.Desc
r.Obsolete = x.objectClass.Obsolete
r.Kind = x.objectClass.Kind
r.SuperClasses = x.objectClass.SuperClasses
r.Must = x.objectClass.Must
r.May = x.objectClass.May
r.Extensions = x.objectClass.Extensions
r.data = x.objectClass.data
r.schema = x.objectClass.schema
r.stringer = x.objectClass.stringer
r.data = x.objectClass.data
}
/*
Maps returns slices of [DefinitionMap] instances.
*/
func (r ObjectClasses) 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 ObjectClass) Map() (def DefinitionMap) {
if !r.Compliant() {
return
}
var sups []string
for i := 0; i < r.SuperClasses().Len(); i++ {
m := r.SuperClasses().Index(i)
sups = append(sups, m.OID())
}
var musts []string
for i := 0; i < r.Must().Len(); i++ {
m := r.Must().Index(i)
musts = append(musts, m.OID())
}
var mays []string
for i := 0; i < r.May().Len(); i++ {
m := r.May().Index(i)
mays = append(mays, 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[`SUP`] = sups
def[`MUST`] = musts
def[`MAY`] = mays
def[`TYPE`] = []string{r.Type()}
def[`RAW`] = []string{r.String()}
switch r.Kind() {
case AbstractKind:
def[`KIND`] = []string{`ABSTRACT`}
case AuxiliaryKind:
def[`KIND`] = []string{`AUXILIARY`}
default:
def[`KIND`] = []string{`STRUCTURAL`}
}
// copy our extensions from receiver r
// into destination def.
def = mapTransferExtensions(r, def)
// Clean up any empty fields
def.clean()
return
}
/*
Compliant returns a Boolean value indicative of every [ObjectClass]
returning a compliant response from the [ObjectClass.Compliant] method.
*/
func (r ObjectClasses) 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.1 of RFC 4512]:
- Numeric OID must be present and valid
- MUST and MAY clause [AttributeTypes] are compliant
- MUST and MAY clause contains no Collective [AttributeType] instances
[§ 4.1.1 of RFC 4512]: https://rfc-editor.org/rfc/rfc4512.html#section-4.1.1
*/
func (r ObjectClass) Compliant() bool {
if r.IsZero() {
return false
}
var (
may AttributeTypes = r.May()
must AttributeTypes = r.Must()
)
for i := 0; i < must.Len(); i++ {
if !must.Index(i).Compliant() || must.Index(i).Collective() {
return false
}
}
for i := 0; i < may.Len(); i++ {
if !may.Index(i).Compliant() || may.Index(i).Collective() {
return false
}
}
ok := isNumericOID(r.NumericOID())
if ok {
r.objectClass.err = nil
}
return ok
}
/*
E returns the underlying error instance.
*/
func (r ObjectClass) E() (err error) {
if !r.IsZero() {
err = r.objectClass.err
} else {
err = ErrNilReceiver
}
return
}
/*
verifySuperClass returns an error following the execution of basic sanity
checks meant to assess the intended super type chain.
*/
func (r *objectClass) verifySuperClass(sup *objectClass) (err error) {
renv := ObjectClass{r}
senv := ObjectClass{sup}
if r == nil || sup == nil {
err = ErrNilInput
}
if renv.NumericOID() == senv.NumericOID() {
// r and sup are the same class
err = mkerr("objectClass is subordinate to itself: " +
renv.NumericOID() + `==` + senv.NumericOID())
} else if renv.SuperClassOf(senv) {
// r is a super class of sup; can't have both!
err = mkerr("cyclical superiority loop: " +
renv.NumericOID() + ` <--> ` + senv.NumericOID())
}
return
}
/*
SuperClassOf returns a Boolean value indicative of r being a superior ("SUP")
[ObjectClass] of sub.
Note: this will trace all super class chains indefinitely and, thus, will
recognize any superior association without regard for "depth".
*/
func (r ObjectClass) SuperClassOf(sub ObjectClass) (sup bool) {
dsups := sub.SuperClasses() // iterated and possibly traversed
for i := 0; i < dsups.Len(); i++ {
dsup := dsups.Index(i)
if sup = dsup.NumericOID() == r.NumericOID(); sup {
// direct (immediate) match
break
} else if sup = r.SuperClassOf(dsup); sup {
// match by traversal
break
}
}
return
}
/*
Obsolete returns a Boolean value indicative of definition
obsolescence.
*/
func (r ObjectClass) Obsolete() (o bool) {
if !r.IsZero() {
o = r.objectClass.Obsolete
}
return
}
/*
SetObsolete sets the receiver instance to OBSOLETE if not already set.
Obsolescence cannot be unset.
This is a fluent method.
*/
func (r ObjectClass) SetObsolete() ObjectClass {
if !r.IsZero() {
r.objectClass.setObsolete()
}
return r
}
func (r *objectClass) setObsolete() {
if !r.Obsolete {
r.Obsolete = true
}
}
/*
Kind returns the uint-based kind value associated with the
receiver instance.
*/
func (r ObjectClass) Kind() (kind uint) {
kind = StructuralKind
if !r.IsZero() {
switch k := r.objectClass.Kind; k {
case AbstractKind:
kind = k
case AuxiliaryKind:
kind = k
}
}
return
}
/*
SuperClasses returns an [ObjectClasses] stack instance containing zero
(0) or more superior [ObjectClass] instances from which the receiver
directly extends. This method does not walk any super class chains.
*/
func (r ObjectClass) SuperClasses() (sups ObjectClasses) {
if !r.IsZero() {
sups = r.objectClass.SuperClasses
}
return
}
/*
SubClasses returns an instance of [ObjectClasses] containing slices of
[ObjectClass] instances that are direct subordinates to the receiver
instance. As such, this method is essentially the inverse of the
[ObjectClass.SuperClasses] method.
The super chain is NOT traversed beyond immediate subordinate instances.
Note that the relevant [Schema] instance must have been set using the
[ObjectClass.SetSchema] method prior to invocation of this method.
Should this requirement remain unfulfilled, the return instance will
be a zero instance.
*/
func (r ObjectClass) SubClasses() (subs ObjectClasses) {
if !r.IsZero() {
subs = NewObjectClassOIDList()
ocs := r.schema().ObjectClasses()
for i := 0; i < ocs.Len(); i++ {
typ := ocs.Index(i)
supers := typ.SuperClasses()
if got := supers.Get(r.NumericOID()); !got.IsZero() {
subs.Push(typ)
}
}
}
return
}
func (r ObjectClass) schema() (s Schema) {
if !r.IsZero() {
s = r.objectClass.schema
}
return
}
/*
SuperChain returns an [ObjectClasses] stack of [ObjectClass] instances
which make up the super type chain of the receiver instance.
*/
func (r ObjectClass) SuperChain() (sups ObjectClasses) {
if !r.IsZero() {
sups = NewObjectClasses()
_sups := r.objectClass.SuperClasses.superChain()
for i := 0; i < _sups.Len(); i++ {
sups.Push(_sups.Index(i))
}
}
return
}
func (r ObjectClasses) superChain() (sups ObjectClasses) {
sups = NewObjectClasses()
for i := 0; i < r.Len(); i++ {
sups.Push(r.Index(i))
_sups := r.Index(i).SuperChain()
for j := 0; j < _sups.Len(); j++ {
sups.Push(_sups.Index(j))
}
}
return
}
/*
Type returns the string literal "objectClass".
*/
func (r ObjectClass) Type() string {
return `objectClass`
}
/*
Type returns the string literal "objectClasses".
*/
func (r ObjectClasses) Type() string {
return `objectClasses`
}
/*
Inventory returns an instance of [Inventory] which represents the current
inventory of [ObjectClass] 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 ObjectClasses) 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
}
/*
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.NewObjectClass] method.
This is a fluent method.
*/
func (r ObjectClass) SetSchema(schema Schema) ObjectClass {
if !r.IsZero() {
r.objectClass.setSchema(schema)
}
return r
}
func (r *objectClass) setSchema(schema Schema) {
r.schema = schema
}
/*
Schema returns the [Schema] instance associated with the receiver instance.
*/
func (r ObjectClass) Schema() (s Schema) {
if !r.IsZero() {
s = r.objectClass.getSchema()
}
return
}
func (r *objectClass) getSchema() (s Schema) {
if r != nil {
s = r.schema
}
return
}
/*
AllMust returns an [AttributeTypes] containing zero (0) or more required
[AttributeType] definitions for use with this class as well as those specified
by any and all applicable super classes. Duplicate references are silently
discarded.
*/
func (r ObjectClass) AllMust() (must AttributeTypes) {
must = NewAttributeTypeOIDList()
if sup := r.SuperClasses(); !sup.IsZero() {
for i := 0; i < sup.len(); i++ {
sm := sup.index(i)
if sc := sm.AllMust(); !sc.IsZero() {
for j := 0; j < sc.len(); j++ {
must.push(sc.index(i))
}
}
}
}
if lm := r.Must(); !lm.IsZero() {
for i := 0; i < lm.len(); i++ {
must.push(lm.index(i))
}
}
return
}
/*
Must returns an [AttributeTypes] containing zero (0) or more required
[AttributeType] definitions for use with this class.
*/
func (r ObjectClass) Must() (must AttributeTypes) {
if !r.IsZero() {
must = r.objectClass.Must
}
return
}
/*
AllMay returns an [AttributeTypes] containing zero (0) or more allowed
[AttributeType] definitions for use with this class as well as those
specified by any and all applicable super classes. Duplicate references
are silently discarded.
*/
func (r ObjectClass) AllMay() (may AttributeTypes) {