-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: encoding/asn1: expose parseTagAndLength #28872
Comments
this is the proposed new code:
|
/cc @agl @FiloSottile |
Adding Proposal-Crypto to put this on @agl and @FiloSottile's queue. I’m aware this is used outside of just crypto. |
In your example the returned I feel like this might be a better fit in golang.org/x/crypto/cryptobyte. Maybe |
I encountered the same issue, we are communicating message encoded using asn over tcp connection, and for receiving message, we need to know the message length to determine the message boundary. My suggestion is make https://github.com/golang/go/blob/master/src/encoding/asn1/asn1.go#L527 this parseTagAndLength func public, so our code could goes like this: func ReadFull(conn net.Conn) ([]byte, error) {
result := bytes.NewBuffer(nil)
var buf [512]byte
for {
n, err := conn.Read(buf[0:])
result.Write(buf[0:n])
if err != nil {
if err == io.EOF {
break
}
return nil, err
}
tagAndLength, offset, err := asn1.ParseTagAndLength(result.Bytes(), 0)
if err == nil {
if (result.Len() - offset) >= tagAndLength.length {
break
}
}
}
return result.Bytes(), nil
} |
ping @agl @FiloSottile |
When working with ldap over the network, the reader does not know in advance the size of the request (the size of the buffer to read).
To know that the full request was read you need to parse the tag and length. This is just about what the function parseTagAndLength does. You only need to add the offset to the length.
To expose this function I suggest adding a public ParseTagAndLength that exposes this functionality and calculates the total expected buffer length.
usage example:
The text was updated successfully, but these errors were encountered: