aboutsummaryrefslogtreecommitdiff
path: root/goldap/extended_response.go
blob: 4e41b0e978ed545380a4eb6cf10499f15530c8d0 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package message

import "fmt"

//
//        ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
//             COMPONENTS OF LDAPResult,
//             responseName     [10] LDAPOID OPTIONAL,
//             responseValue    [11] OCTET STRING OPTIONAL }

func (extended *ExtendedResponse) SetResponseName(name LDAPOID) {
	extended.responseName = &name
}

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

func (extended *ExtendedResponse) readComponents(bytes *Bytes) (err error) {
	extended.LDAPResult.readComponents(bytes)
	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 == TagExtendedResponseName {
			var oid LDAPOID
			oid, err = readTaggedLDAPOID(bytes, classContextSpecific, TagExtendedResponseName)
			if err != nil {
				err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
				return
			}
			extended.responseName = oid.Pointer()
		}
	}
	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 == TagExtendedResponseValue {
			var responseValue OCTETSTRING
			responseValue, err = readTaggedOCTETSTRING(bytes, classContextSpecific, TagExtendedResponseValue)
			if err != nil {
				err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
				return
			}
			extended.responseValue = responseValue.Pointer()
		}
	}
	return
}

func (extended ExtendedResponse) write(bytes *Bytes) (size int) {
	if extended.responseValue != nil {
		size += extended.responseValue.writeTagged(bytes, classContextSpecific, TagExtendedResponseValue)
	}
	if extended.responseName != nil {
		size += extended.responseName.writeTagged(bytes, classContextSpecific, TagExtendedResponseName)
	}
	size += extended.LDAPResult.writeComponents(bytes)
	size += bytes.WriteTagAndLength(classApplication, isCompound, TagExtendedResponse, size)
	return
}

func (extended ExtendedResponse) size() (size int) {
	size += extended.LDAPResult.sizeComponents()
	if extended.responseName != nil {
		size += extended.responseName.sizeTagged(TagExtendedResponseName)
	}
	if extended.responseValue != nil {
		size += extended.responseValue.sizeTagged(TagExtendedResponseValue)
	}
	size += sizeTagAndLength(TagExtendedResponse, size)
	return
}