aboutsummaryrefslogtreecommitdiff
path: root/goldap/intermediate_response.go
blob: 90bf188258ea8279af50d153d888a5301ff07586 (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
86
87
88
89
package message

import "fmt"

//
//        IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
//             responseName     [0] LDAPOID OPTIONAL,
//             responseValue    [1] OCTET STRING OPTIONAL }
func readIntermediateResponse(bytes *Bytes) (ret IntermediateResponse, err error) {
	err = bytes.ReadSubBytes(classApplication, TagIntermediateResponse, ret.readComponents)
	if err != nil {
		err = LdapError{fmt.Sprintf("readIntermediateResponse:\n%s", err.Error())}
		return
	}
	return
}
func (bytes *Bytes) PreviewTagAndLength() (tagAndLength TagAndLength, err error) {
	previousOffset := bytes.offset // Save offset
	tagAndLength, err = bytes.ParseTagAndLength()
	bytes.offset = previousOffset // Restore offset
	return
}
func (res *IntermediateResponse) readComponents(bytes *Bytes) (err error) {
	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 == TagIntermediateResponseName {
			var oid LDAPOID
			oid, err = readTaggedLDAPOID(bytes, classContextSpecific, TagIntermediateResponseName)
			if err != nil {
				err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
				return
			}
			res.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 == TagIntermediateResponseValue {
			var str OCTETSTRING
			str, err = readTaggedOCTETSTRING(bytes, classContextSpecific, TagIntermediateResponseValue)
			if err != nil {
				err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
				return
			}
			res.responseValue = str.Pointer()
		}
	}
	return
}

//
//        IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
//             responseName     [0] LDAPOID OPTIONAL,
//             responseValue    [1] OCTET STRING OPTIONAL }
func (i IntermediateResponse) write(bytes *Bytes) (size int) {
	if i.responseValue != nil {
		size += i.responseValue.writeTagged(bytes, classContextSpecific, TagIntermediateResponseValue)
	}
	if i.responseName != nil {
		size += i.responseName.writeTagged(bytes, classContextSpecific, TagIntermediateResponseName)
	}
	size += bytes.WriteTagAndLength(classApplication, isCompound, TagIntermediateResponse, size)
	return
}

//
//        IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
//             responseName     [0] LDAPOID OPTIONAL,
//             responseValue    [1] OCTET STRING OPTIONAL }
func (i IntermediateResponse) size() (size int) {
	if i.responseName != nil {
		size += i.responseName.sizeTagged(TagIntermediateResponseName)
	}
	if i.responseValue != nil {
		size += i.responseValue.sizeTagged(TagIntermediateResponseValue)
	}
	size += sizeTagAndLength(TagIntermediateResponse, size)
	return
}