aboutsummaryrefslogtreecommitdiff
path: root/goldap/bind_request.go
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2021-09-16 13:41:01 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2021-09-16 13:41:01 +0200
commit477d7014edc787ba9a977acd19fcbfc55531768b (patch)
treeac8b65be8634fa9526cd727da60893244d11e88a /goldap/bind_request.go
parenta53641e773730ba171df2602c8d199968d6e6447 (diff)
downloadbottin-477d7014edc787ba9a977acd19fcbfc55531768b.tar.gz
bottin-477d7014edc787ba9a977acd19fcbfc55531768b.zip
Vendor goldap
Diffstat (limited to 'goldap/bind_request.go')
-rw-r--r--goldap/bind_request.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/goldap/bind_request.go b/goldap/bind_request.go
new file mode 100644
index 0000000..d00a3ef
--- /dev/null
+++ b/goldap/bind_request.go
@@ -0,0 +1,93 @@
+package message
+
+import "fmt"
+
+// BindRequest ::= [APPLICATION 0] SEQUENCE {
+// version INTEGER (1 .. 127),
+// name LDAPDN,
+// authentication AuthenticationChoice }
+
+func (request *BindRequest) Name() LDAPDN {
+ return request.name
+}
+
+func (request *BindRequest) Authentication() AuthenticationChoice {
+ return request.authentication
+}
+
+func (request *BindRequest) AuthenticationSimple() OCTETSTRING {
+ return request.Authentication().(OCTETSTRING)
+}
+
+func (request *BindRequest) AuthenticationChoice() string {
+ switch request.Authentication().(type) {
+ case OCTETSTRING:
+ return "simple"
+ case SaslCredentials:
+ return "sasl"
+ }
+ return ""
+}
+
+func readBindRequest(bytes *Bytes) (bindrequest BindRequest, err error) {
+ err = bytes.ReadSubBytes(classApplication, TagBindRequest, bindrequest.readComponents)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readBindRequest:\n%s", err.Error())}
+ return
+ }
+ return
+}
+
+func (request *BindRequest) readComponents(bytes *Bytes) (err error) {
+ request.version, err = readINTEGER(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ if !(request.version >= BindRequestVersionMin && request.version <= BindRequestVersionMax) {
+ err = LdapError{fmt.Sprintf("readComponents: invalid version %d, must be between %d and %d", request.version, BindRequestVersionMin, BindRequestVersionMax)}
+ return
+ }
+ request.name, err = readLDAPDN(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ request.authentication, err = readAuthenticationChoice(bytes)
+ if err != nil {
+ err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
+ return
+ }
+ return
+}
+
+func (request BindRequest) write(bytes *Bytes) (size int) {
+ switch request.authentication.(type) {
+ case OCTETSTRING:
+ size += request.authentication.(OCTETSTRING).writeTagged(bytes, classContextSpecific, TagAuthenticationChoiceSimple)
+ case SaslCredentials:
+ size += request.authentication.(SaslCredentials).writeTagged(bytes, classContextSpecific, TagAuthenticationChoiceSaslCredentials)
+ default:
+ panic(fmt.Sprintf("Unknown authentication choice: %#v", request.authentication))
+ }
+ size += request.name.write(bytes)
+ size += request.version.write(bytes)
+ size += bytes.WriteTagAndLength(classApplication, isCompound, TagBindRequest, size)
+ return
+}
+
+func (request BindRequest) size() (size int) {
+ size += request.version.size()
+ size += request.name.size()
+ switch request.authentication.(type) {
+ case OCTETSTRING:
+ size += request.authentication.(OCTETSTRING).sizeTagged(TagAuthenticationChoiceSimple)
+ case SaslCredentials:
+ size += request.authentication.(SaslCredentials).sizeTagged(TagAuthenticationChoiceSaslCredentials)
+ default:
+ panic(fmt.Sprintf("Unknown authentication choice: %#v", request.authentication))
+ }
+
+ size += sizeTagAndLength(TagBindRequest, size)
+ return
+}