Skip to content

Commit

Permalink
[MOD] Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lor00x committed Jun 18, 2018
1 parent 2d4d64f commit a546dff
Show file tree
Hide file tree
Showing 49 changed files with 612 additions and 817 deletions.
15 changes: 6 additions & 9 deletions message/abandon_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import "fmt"

//
// AbandonRequest ::= [APPLICATION 16] MessageID
func (a AbandonRequest) size() int {
return MessageID(a).sizeTagged(TagAbandonRequest)
}

//
// AbandonRequest ::= [APPLICATION 16] MessageID
func readAbandonRequest(bytes *Bytes) (ret AbandonRequest, err error) {
var mes MessageID
mes, err = readTaggedMessageID(bytes, classApplication, TagAbandonRequest)
Expand All @@ -21,8 +16,10 @@ func readAbandonRequest(bytes *Bytes) (ret AbandonRequest, err error) {
return
}

//
// AbandonRequest ::= [APPLICATION 16] MessageID
func (a AbandonRequest) write(bytes *Bytes) int {
return MessageID(a).writeTagged(bytes, classApplication, TagAbandonRequest)
func (abandon AbandonRequest) size() int {
return MessageID(abandon).sizeTagged(TagAbandonRequest)
}

func (abandon AbandonRequest) write(bytes *Bytes) int {
return MessageID(abandon).writeTagged(bytes, classApplication, TagAbandonRequest)
}
73 changes: 21 additions & 52 deletions message/add_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ package message

import "fmt"

//
//
//
//
//
//
//Sermersheim Standards Track [Page 58]
//
//
//RFC 4511 LDAPv3 June 2006
//
//
// AddRequest ::= [APPLICATION 8] SEQUENCE {
// entry LDAPDN,
// attributes AttributeList }

func (add *AddRequest) Entry() LDAPDN {
return add.entry
}

func (add *AddRequest) Attributes() AttributeList {
return add.attributes
}

func readAddRequest(bytes *Bytes) (ret AddRequest, err error) {
err = bytes.ReadSubBytes(classApplication, TagAddRequest, ret.readComponents)
if err != nil {
Expand All @@ -25,60 +23,31 @@ func readAddRequest(bytes *Bytes) (ret AddRequest, err error) {
}
return
}
func (req *AddRequest) readComponents(bytes *Bytes) (err error) {
req.entry, err = readLDAPDN(bytes)

func (add *AddRequest) readComponents(bytes *Bytes) (err error) {
add.entry, err = readLDAPDN(bytes)
if err != nil {
err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
return
}
req.attributes, err = readAttributeList(bytes)
add.attributes, err = readAttributeList(bytes)
if err != nil {
err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
return
}
return
}

//
//
//
//
//
//
//Sermersheim Standards Track [Page 58]
//
//
//RFC 4511 LDAPv3 June 2006
//
//
// AddRequest ::= [APPLICATION 8] SEQUENCE {
// entry LDAPDN,
// attributes AttributeList }
func (a AddRequest) write(bytes *Bytes) (size int) {
size += a.attributes.write(bytes)
size += a.entry.write(bytes)
size += bytes.WriteTagAndLength(classApplication, isCompound, TagAddRequest, size)
func (add AddRequest) size() (size int) {
size += add.entry.size()
size += add.attributes.size()
size += sizeTagAndLength(TagAddRequest, size)
return
}

//
//
//
//
//
//
//Sermersheim Standards Track [Page 58]
//
//
//RFC 4511 LDAPv3 June 2006
//
//
// AddRequest ::= [APPLICATION 8] SEQUENCE {
// entry LDAPDN,
// attributes AttributeList }
func (a AddRequest) size() (size int) {
size += a.entry.size()
size += a.attributes.size()
size += sizeTagAndLength(TagAddRequest, size)
func (add AddRequest) write(bytes *Bytes) (size int) {
size += add.attributes.write(bytes)
size += add.entry.write(bytes)
size += bytes.WriteTagAndLength(classApplication, isCompound, TagAddRequest, size)
return
}
16 changes: 8 additions & 8 deletions message/add_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import "fmt"

//
// AddResponse ::= [APPLICATION 9] LDAPResult

func (l *AddResponse) SetResultCode(code int) {
l.resultCode = ENUMERATED(code)
}

func readAddResponse(bytes *Bytes) (ret AddResponse, err error) {
var res LDAPResult
res, err = readTaggedLDAPResult(bytes, classApplication, TagAddResponse)
Expand All @@ -15,14 +20,9 @@ func readAddResponse(bytes *Bytes) (ret AddResponse, err error) {
return
}

//
// AddResponse ::= [APPLICATION 9] LDAPResult
func (a AddResponse) write(bytes *Bytes) int {
return LDAPResult(a).writeTagged(bytes, classApplication, TagAddResponse)
}

//
// AddResponse ::= [APPLICATION 9] LDAPResult
func (a AddResponse) size() int {
return LDAPResult(a).sizeTagged(TagAddResponse)
}
func (a AddResponse) write(bytes *Bytes) int {
return LDAPResult(a).writeTagged(bytes, classApplication, TagAddResponse)
}
28 changes: 11 additions & 17 deletions message/assertion_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "fmt"

//
// AssertionValue ::= OCTET STRING

func readAssertionValue(bytes *Bytes) (assertionvalue AssertionValue, err error) {
var octetstring OCTETSTRING
octetstring, err = readOCTETSTRING(bytes)
Expand All @@ -14,6 +15,7 @@ func readAssertionValue(bytes *Bytes) (assertionvalue AssertionValue, err error)
assertionvalue = AssertionValue(octetstring)
return
}

func readTaggedAssertionValue(bytes *Bytes, class int, tag int) (assertionvalue AssertionValue, err error) {
var octetstring OCTETSTRING
octetstring, err = readTaggedOCTETSTRING(bytes, class, tag)
Expand All @@ -25,26 +27,18 @@ func readTaggedAssertionValue(bytes *Bytes, class int, tag int) (assertionvalue
return
}

//
// AssertionValue ::= OCTET STRING
func (a AssertionValue) write(bytes *Bytes) int {
return OCTETSTRING(a).write(bytes)
}
func (a AssertionValue) writeTagged(bytes *Bytes, class int, tag int) int {
return OCTETSTRING(a).writeTagged(bytes, class, tag)
func (assertion AssertionValue) size() int {
return OCTETSTRING(assertion).size()
}

//
// AttributeValue ::= OCTET STRING
func (a AttributeValue) size() int {
return OCTETSTRING(a).size()
func (assertion AssertionValue) sizeTagged(tag int) int {
return OCTETSTRING(assertion).sizeTagged(tag)
}

//
// AssertionValue ::= OCTET STRING
func (a AssertionValue) size() int {
return OCTETSTRING(a).size()
func (assertion AssertionValue) write(bytes *Bytes) int {
return OCTETSTRING(assertion).write(bytes)
}
func (a AssertionValue) sizeTagged(tag int) int {
return OCTETSTRING(a).sizeTagged(tag)

func (assertion AssertionValue) writeTagged(bytes *Bytes, class int, tag int) int {
return OCTETSTRING(assertion).writeTagged(bytes, class, tag)
}
25 changes: 13 additions & 12 deletions message/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import "fmt"
// Attribute ::= PartialAttribute(WITH COMPONENTS {
// ...,
// vals (SIZE(1..MAX))})

func (attribute *Attribute) Type_() AttributeDescription {
return attribute.type_
}

func (attribute *Attribute) Vals() []AttributeValue {
return attribute.vals
}

func readAttribute(bytes *Bytes) (ret Attribute, err error) {
var par PartialAttribute
par, err = readPartialAttribute(bytes)
Expand All @@ -22,18 +31,10 @@ func readAttribute(bytes *Bytes) (ret Attribute, err error) {

}

//
// Attribute ::= PartialAttribute(WITH COMPONENTS {
// ...,
// vals (SIZE(1..MAX))})
func (a Attribute) write(bytes *Bytes) (size int) {
return PartialAttribute(a).write(bytes)
func (attribute Attribute) size() (size int) {
return PartialAttribute(attribute).size()
}

//
// Attribute ::= PartialAttribute(WITH COMPONENTS {
// ...,
// vals (SIZE(1..MAX))})
func (a Attribute) size() (size int) {
return PartialAttribute(a).size()
func (attribute Attribute) write(bytes *Bytes) (size int) {
return PartialAttribute(attribute).write(bytes)
}
31 changes: 14 additions & 17 deletions message/attribute_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import "fmt"
// AttributeDescription ::= LDAPString
// -- Constrained to <attributedescription>
// -- [RFC4512]

func (description AttributeDescription) Pointer() *AttributeDescription { return &description }

func readAttributeDescription(bytes *Bytes) (ret AttributeDescription, err error) {
var ldapstring LDAPString
ldapstring, err = readLDAPString(bytes)
Expand All @@ -17,6 +20,7 @@ func readAttributeDescription(bytes *Bytes) (ret AttributeDescription, err error
ret = AttributeDescription(ldapstring)
return
}

func readTaggedAttributeDescription(bytes *Bytes, class int, tag int) (ret AttributeDescription, err error) {
var ldapstring LDAPString
ldapstring, err = readTaggedLDAPString(bytes, class, tag)
Expand All @@ -28,26 +32,19 @@ func readTaggedAttributeDescription(bytes *Bytes, class int, tag int) (ret Attri
ret = AttributeDescription(ldapstring)
return
}
func (a AttributeDescription) Pointer() *AttributeDescription { return &a }

//
// AttributeDescription ::= LDAPString
// -- Constrained to <attributedescription>
// -- [RFC4512]
func (a AttributeDescription) write(bytes *Bytes) int {
return LDAPString(a).write(bytes)
func (description AttributeDescription) size() int {
return LDAPString(description).size()
}
func (a AttributeDescription) writeTagged(bytes *Bytes, class int, tag int) int {
return LDAPString(a).writeTagged(bytes, class, tag)

func (description AttributeDescription) sizeTagged(tag int) int {
return LDAPString(description).sizeTagged(tag)
}

//
// AttributeDescription ::= LDAPString
// -- Constrained to <attributedescription>
// -- [RFC4512]
func (a AttributeDescription) size() int {
return LDAPString(a).size()
func (description AttributeDescription) write(bytes *Bytes) int {
return LDAPString(description).write(bytes)
}
func (a AttributeDescription) sizeTagged(tag int) int {
return LDAPString(a).sizeTagged(tag)

func (description AttributeDescription) writeTagged(bytes *Bytes, class int, tag int) int {
return LDAPString(description).writeTagged(bytes, class, tag)
}
21 changes: 9 additions & 12 deletions message/attribute_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "fmt"

//
// AttributeList ::= SEQUENCE OF attribute Attribute

func readAttributeList(bytes *Bytes) (ret AttributeList, err error) {
err = bytes.ReadSubBytes(classUniversal, tagSequence, ret.readComponents)
if err != nil {
Expand All @@ -25,22 +26,18 @@ func (list *AttributeList) readComponents(bytes *Bytes) (err error) {
return
}

//
// AttributeList ::= SEQUENCE OF attribute Attribute
func (a AttributeList) write(bytes *Bytes) (size int) {
for i := len(a) - 1; i >= 0; i-- {
size += a[i].write(bytes)
func (list AttributeList) size() (size int) {
for _, att := range list {
size += att.size()
}
size += bytes.WriteTagAndLength(classUniversal, isCompound, tagSequence, size)
size += sizeTagAndLength(tagSequence, size)
return
}

//
// AttributeList ::= SEQUENCE OF attribute Attribute
func (a AttributeList) size() (size int) {
for _, att := range a {
size += att.size()
func (list AttributeList) write(bytes *Bytes) (size int) {
for i := len(list) - 1; i >= 0; i-- {
size += list[i].write(bytes)
}
size += sizeTagAndLength(tagSequence, size)
size += bytes.WriteTagAndLength(classUniversal, isCompound, tagSequence, size)
return
}
23 changes: 8 additions & 15 deletions message/attribute_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "fmt"
// AttributeSelection ::= SEQUENCE OF selector LDAPString
// -- The LDAPString is constrained to
// -- <attributeSelector> in Section 4.5.1.8

func readAttributeSelection(bytes *Bytes) (attributeSelection AttributeSelection, err error) {
err = bytes.ReadSubBytes(classUniversal, tagSequence, attributeSelection.readComponents)
if err != nil {
Expand All @@ -14,7 +15,7 @@ func readAttributeSelection(bytes *Bytes) (attributeSelection AttributeSelection
}
return
}
func (attributeSelection *AttributeSelection) readComponents(bytes *Bytes) (err error) {
func (selection *AttributeSelection) readComponents(bytes *Bytes) (err error) {
for bytes.HasMoreData() {
var ldapstring LDAPString
ldapstring, err = readLDAPString(bytes)
Expand All @@ -23,29 +24,21 @@ func (attributeSelection *AttributeSelection) readComponents(bytes *Bytes) (err
err = LdapError{fmt.Sprintf("readComponents:\n%s", err.Error())}
return
}
*attributeSelection = append(*attributeSelection, ldapstring)
*selection = append(*selection, ldapstring)
}
return
}

//
// AttributeSelection ::= SEQUENCE OF selector LDAPString
// -- The LDAPString is constrained to
// -- <attributeSelector> in Section 4.5.1.8
func (a AttributeSelection) write(bytes *Bytes) (size int) {
for i := len(a) - 1; i >= 0; i-- {
size += a[i].write(bytes)
func (selection AttributeSelection) write(bytes *Bytes) (size int) {
for i := len(selection) - 1; i >= 0; i-- {
size += selection[i].write(bytes)
}
size += bytes.WriteTagAndLength(classUniversal, isCompound, tagSequence, size)
return
}

//
// AttributeSelection ::= SEQUENCE OF selector LDAPString
// -- The LDAPString is constrained to
// -- <attributeSelector> in Section 4.5.1.8
func (a AttributeSelection) size() (size int) {
for _, selector := range a {
func (selection AttributeSelection) size() (size int) {
for _, selector := range selection {
size += selector.size()
}
size += sizeTagAndLength(tagSequence, size)
Expand Down

0 comments on commit a546dff

Please sign in to comment.