Esempio n. 1
0
func mustMarshal(val interface{}, params string) []byte {
	data, err := asn1.MarshalWithParams(val, params)
	if err != nil {
		panic(err)
	}
	return data
}
Esempio n. 2
0
func (n Not) marshal() ([]byte, error) {
	f, err := n.Filter.marshal()
	if err != nil {
		return nil, err
	}
	return asn1.MarshalWithParams(asn1.RawValue{FullBytes: f}, notParam)
}
Esempio n. 3
0
func (o Or) marshal() (data []byte, err error) {
	filters := make([]asn1.RawValue, len(o))
	for i, f := range o {
		if filters[i].FullBytes, err = f.marshal(); err != nil {
			return nil, err
		}
	}
	return asn1.MarshalWithParams(filterSet{filters}, orParam)
}
Esempio n. 4
0
func (s *authSock) Write(b []byte) (int, error) {
	if s.finished {
		sz := [4]byte{}
		binary.BigEndian.PutUint32(sz[:], uint32(len(b)))
		if _, err := s.Conn.Write(sz[:]); err != nil {
			return 0, err
		}

		return s.Conn.Write(b)
	}

	if s.waitReply {
		if _, err := s.Read(nil); err != nil {
			return 0, err
		}
	}

	var err error

	req := bindRequest{
		Version: ldapVersion,
	}

	if s.mech == "SIMPLE" {
		idx := bytes.IndexByte(b, 0)
		req.BindDN = b[:idx]
		req.Auth.FullBytes, err = asn1.MarshalWithParams(b[idx+1:], simpleBindParam)
	} else {
		req.Auth.FullBytes, err = asn1.MarshalWithParams(saslCredentials{[]byte(s.mech), b}, saslBindParam)
	}

	if err != nil {
		return 0, err
	}

	if err := dosend(s.Conn, bindRequestParam, req); err != nil {
		return 0, err
	}

	s.waitReply = true

	return len(b), nil
}
Esempio n. 5
0
func (db *DB) send(param string, req interface{}, reply replyHandler) error {
	data, err := asn1.MarshalWithParams(req, param)
	if err != nil {
		return err
	}

	db.lk.Lock()
	defer db.lk.Unlock()

	if db.closed {
		return ErrClosed
	}

	if db.conn == nil {
		rw, conn, err := open(db.url, db.cfg)
		if err != nil {
			return err
		}

		db.conn = conn
		db.rw = rw
		go db.rxThread(rw, conn)
	}

	id := db.nextId
	db.nextId++

	msg := message{
		Id: id,
		Data: asn1.RawValue{
			FullBytes: data,
		},
	}

	out, err := asn1.Marshal(msg)
	if err != nil {
		return err
	}

	if _, err := db.rw.Write(out); err != nil {
		return err
	}

	if reply != nil {
		db.replies[id] = reply
	}

	return nil
}
Esempio n. 6
0
func dosend(rw io.ReadWriter, param string, req interface{}) error {
	rdata, err := asn1.MarshalWithParams(req, param)
	if err != nil {
		return err
	}

	msg := message{
		Id: 0,
		Data: asn1.RawValue{
			FullBytes: rdata,
		},
	}

	mdata, err := asn1.Marshal(msg)
	if err != nil {
		return err
	}

	if _, err := rw.Write(mdata); err != nil {
		return err
	}

	return nil
}
Esempio n. 7
0
func (p Present) marshal() ([]byte, error) {
	return asn1.MarshalWithParams([]byte(p), presentParam)
}
Esempio n. 8
0
func (e LessOrEqual) marshal() ([]byte, error) {
	return asn1.MarshalWithParams(assertion{[]byte(e.Attr), e.Value}, lessOrEqualParam)
}