Example #1
0
func getresult(rw io.ReadWriter, param string, res *result) error {
	// We need to be careful about only reading the response and no more
	// so this can work with start tls
	var b []byte
	var err error
	var de, he int

	if b, err = readExactly(rw, b, 2); err != nil {
		return err
	}

	if he, err = headerEnd(b); err != nil {
		return err
	}

	if b, err = readExactly(rw, b, he); err != nil {
		return err
	}

	if de, err = dataEnd(b); err != nil {
		return err
	}

	if b, err = readExactly(rw, b, de); err != nil {
		return err
	}

	msg := message{}
	if _, err := asn1.Unmarshal(b, &msg); err != nil {
		return err
	}

	if msg.Id != 0 {
		return ErrProtocol
	}

	if _, err := asn1.UnmarshalWithParams(msg.Data.FullBytes, res, param); err != nil {
		return err
	}

	return nil
}
Example #2
0
func mustUnmarshal(data []byte, val interface{}, params string) {
	if _, err := asn1.UnmarshalWithParams(data, val, params); err != nil {
		panic(err)
	}
}