aboutsummaryrefslogtreecommitdiff
path: root/goldap/matching_rule_assertion.go
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2021-07-07 01:49:33 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2021-09-16 13:09:26 +0200
commit563fc272a36c8be317fbe95c8308ca2dfa29c3aa (patch)
tree0b6f9a6a15516e7234fc928ecbebbd32d3154074 /goldap/matching_rule_assertion.go
parentaa912b5ceb24cb8772709171ea9589b0771bbe54 (diff)
downloadbottin-563fc272a36c8be317fbe95c8308ca2dfa29c3aa.tar.gz
bottin-563fc272a36c8be317fbe95c8308ca2dfa29c3aa.zip
Vendor goldap, fix ASN.1 BER integer and length encoding
- Add tests for goldap to prevent regressions - Disable reconnection for our functional tests
Diffstat (limited to 'goldap/matching_rule_assertion.go')
-rw-r--r--goldap/matching_rule_assertion.go117
1 files changed, 117 insertions, 0 deletions
diff --git a/goldap/matching_rule_assertion.go b/goldap/matching_rule_assertion.go
new file mode 100644
index 0000000..e137852
--- /dev/null
+++ b/goldap/matching_rule_assertion.go
@@ -0,0 +1,117 @@
+package message
+
+import "fmt"
+
+//
+// MatchingRuleAssertion ::= SEQUENCE {
+// matchingRule [1] MatchingRuleId OPTIONAL,
+// type [2] AttributeDescription OPTIONAL,
+// matchValue [3] AssertionValue,
+// dnAttributes [4] BOOLEAN DEFAULT FALSE }
+func readTaggedMatchingRuleAssertion(bytes *Bytes, class int, tag int) (ret MatchingRuleAssertion, err error) {
+ err = bytes.ReadSubBytes(class, tag, ret.readComponents)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readTaggedMatchingRuleAssertion:\n%s", err.Error())}
+ return
+ }
+ return
+}
+func (matchingruleassertion *MatchingRuleAssertion) readComponents(bytes *Bytes) (err error) {
+ err = matchingruleassertion.readMatchingRule(bytes)
+ if err != nil {
+ return LdapError{fmt.Sprintf("readComponents: %s", err.Error())}
+ }
+ err = matchingruleassertion.readType(bytes)
+ if err != nil {
+ return LdapError{fmt.Sprintf("readComponents: %s", err.Error())}
+ }
+ matchingruleassertion.matchValue, err = readTaggedAssertionValue(bytes, classContextSpecific, TagMatchingRuleAssertionMatchValue)
+ if err != nil {
+ return LdapError{fmt.Sprintf("readComponents: %s", err.Error())}
+ }
+ matchingruleassertion.dnAttributes, err = readTaggedBOOLEAN(bytes, classContextSpecific, TagMatchingRuleAssertionDnAttributes)
+ if err != nil {
+ return LdapError{fmt.Sprintf("readComponents: %s", err.Error())}
+ }
+ return
+}
+func (matchingruleassertion *MatchingRuleAssertion) readMatchingRule(bytes *Bytes) (err error) {
+ var tagAndLength TagAndLength
+ tagAndLength, err = bytes.PreviewTagAndLength()
+ if err != nil {
+ return LdapError{fmt.Sprintf("readMatchingRule: %s", err.Error())}
+ }
+ if tagAndLength.Tag == TagMatchingRuleAssertionMatchingRule {
+ var matchingRule MatchingRuleId
+ matchingRule, err = readTaggedMatchingRuleId(bytes, classContextSpecific, TagMatchingRuleAssertionMatchingRule)
+ if err != nil {
+ return LdapError{fmt.Sprintf("readMatchingRule: %s", err.Error())}
+ }
+ matchingruleassertion.matchingRule = matchingRule.Pointer()
+ }
+ return
+}
+func (matchingruleassertion *MatchingRuleAssertion) readType(bytes *Bytes) (err error) {
+ var tagAndLength TagAndLength
+ tagAndLength, err = bytes.PreviewTagAndLength()
+ if err != nil {
+ return LdapError{fmt.Sprintf("readType: %s", err.Error())}
+ }
+ if tagAndLength.Tag == TagMatchingRuleAssertionType {
+ var attributedescription AttributeDescription
+ attributedescription, err = readTaggedAttributeDescription(bytes, classContextSpecific, TagMatchingRuleAssertionType)
+ if err != nil {
+ return LdapError{fmt.Sprintf("readType: %s", err.Error())}
+ }
+ matchingruleassertion.type_ = &attributedescription
+ }
+ return
+}
+func (m MatchingRuleAssertion) writeTagged(bytes *Bytes, class int, tag int) (size int) {
+ if m.dnAttributes != BOOLEAN(false) {
+ size += m.dnAttributes.writeTagged(bytes, classContextSpecific, TagMatchingRuleAssertionDnAttributes)
+ }
+ size += m.matchValue.writeTagged(bytes, classContextSpecific, TagMatchingRuleAssertionMatchValue)
+ if m.type_ != nil {
+ size += m.type_.writeTagged(bytes, classContextSpecific, TagMatchingRuleAssertionType)
+ }
+ if m.matchingRule != nil {
+ size += m.matchingRule.writeTagged(bytes, classContextSpecific, TagMatchingRuleAssertionMatchingRule)
+ }
+ size += bytes.WriteTagAndLength(class, isCompound, tag, size)
+ return
+}
+
+//
+// MatchingRuleAssertion ::= SEQUENCE {
+// matchingRule [1] MatchingRuleId OPTIONAL,
+// type [2] AttributeDescription OPTIONAL,
+// matchValue [3] AssertionValue,
+// dnAttributes [4] BOOLEAN DEFAULT FALSE }
+func (m MatchingRuleAssertion) write(bytes *Bytes) (size int) {
+ return m.writeTagged(bytes, classUniversal, tagSequence)
+}
+
+//
+// MatchingRuleAssertion ::= SEQUENCE {
+// matchingRule [1] MatchingRuleId OPTIONAL,
+// type [2] AttributeDescription OPTIONAL,
+// matchValue [3] AssertionValue,
+// dnAttributes [4] BOOLEAN DEFAULT FALSE }
+func (m MatchingRuleAssertion) size() (size int) {
+ return m.sizeTagged(tagSequence)
+}
+func (m MatchingRuleAssertion) sizeTagged(tag int) (size int) {
+ if m.matchingRule != nil {
+ size += m.matchingRule.sizeTagged(TagMatchingRuleAssertionMatchingRule)
+ }
+ if m.type_ != nil {
+ size += m.type_.sizeTagged(TagMatchingRuleAssertionType)
+ }
+ size += m.matchValue.sizeTagged(TagMatchingRuleAssertionMatchValue)
+ if m.dnAttributes != BOOLEAN(false) {
+ size += m.dnAttributes.sizeTagged(TagMatchingRuleAssertionDnAttributes)
+ }
+ size += sizeTagAndLength(tag, size)
+ return
+}