aboutsummaryrefslogtreecommitdiff
path: root/goldap/extended_request.go
blob: 983ebf98bac51d7bcdf40c2fb3f82f5c562a2e49 (plain) (blame)
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
package message

import "fmt"

//
//        ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
//             requestName      [0] LDAPOID,
//             requestValue     [1] OCTET STRING OPTIONAL }

func (extended *ExtendedRequest) RequestName() LDAPOID {
	return extended.requestName
}

func (extended *ExtendedRequest) RequestValue() *OCTETSTRING {
	return extended.requestValue
}

func readExtendedRequest(bytes *Bytes) (ret ExtendedRequest, err error) {
	err = bytes.ReadSubBytes(classApplication, TagExtendedRequest, ret.readComponents)
	if err != nil {
		err = LdapError{fmt.Sprintf("readExtendedRequest:\n%s", err.Error())}
		return
	}
	return
}

func (extended *ExtendedRequest) readComponents(bytes *Bytes) (err error) {
	extended.requestName, err = readTaggedLDAPOID(bytes, classContextSpecific, TagExtendedRequestName)
	if err != nil {
		err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
		return
	}
	if bytes.HasMoreData() {
		var tag TagAndLength
		tag, err = bytes.PreviewTagAndLength()
		if err != nil {
			err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
			return
		}
		if tag.Tag == TagExtendedRequestValue {
			var requestValue OCTETSTRING
			requestValue, err = readTaggedOCTETSTRING(bytes, classContextSpecific, TagExtendedRequestValue)
			if err != nil {
				err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
				return
			}
			extended.requestValue = requestValue.Pointer()
		}
	}
	return
}

func (extended ExtendedRequest) write(bytes *Bytes) (size int) {
	if extended.requestValue != nil {
		size += extended.requestValue.writeTagged(bytes, classContextSpecific, TagExtendedRequestValue)
	}
	size += extended.requestName.writeTagged(bytes, classContextSpecific, TagExtendedRequestName)
	size += bytes.WriteTagAndLength(classApplication, isCompound, TagExtendedRequest, size)
	return
}

func (extended ExtendedRequest) size() (size int) {
	size += extended.requestName.sizeTagged(TagExtendedRequestName)
	if extended.requestValue != nil {
		size += extended.requestValue.sizeTagged(TagExtendedRequestValue)
	}
	size += sizeTagAndLength(TagExtendedRequest, size)
	return
}