Comments (3)
Hey @Fasjeit. Thanks for pointing that out
return 2 + length, errors.New("disco: cannot decrypt the payload")
I tried to mirror crypto/tls code but noticed that it often returned an information-less 0 when there was an error.
return 0, err
I thought we could be more useful and use that return value even when there was an error. But indeed I do not know exactly how it could be useful.
If you think this is adding ambiguity, perhaps it is a good argument for constantly replacing that value with 0
. Notice that in one point crypto/tls does return a more accurate length of byte read with an error.
from disco.
Looks like in tls non-zero return value is obtained here
n, err = c.input.Read(b)
so output value n in this case is always related to output value b. Basically it means "we managed to read something from input connection before, here is your data, here is it's length, but looks like there is an error when we are trying to read more."
In case of disco we return
return 2 + length, errors.New("disco: cannot decrypt the payload")
which not only does no good to user, but also preventing him from getting correct length of data, stored in buffer b after function call. It means "there is an error, we are not going to tell you how to truncate the buffer b to get at least some data we cached before, but instead here is the number of raw bytes from connection we managed to read."
If you want to copy tls it will probably be better to return readSoFar value in case of errors, so user can get correct data length, if it was read from inputBuffer.
// read whatever there is to read in the buffer
readSoFar := 0
if len(c.inputBuffer) > 0 {
copy(b, c.inputBuffer)
if len(c.inputBuffer) >= len(b) {
c.inputBuffer = c.inputBuffer[len(b):]
return len(b), nil
}
readSoFar += len(c.inputBuffer)
c.inputBuffer = c.inputBuffer[:0]
}
// read header from socket
bufHeader, err := readFromUntil(c.conn, 2)
if err != nil {
// already read readSoFar bytes to b
return readSoFar, err
}
// -> same thing for errors below
from disco.
Ah I see what you mean, there is a difference between:
- we read
n
bytes (which is what we're doing here) - we filled
n
bytes in theb
buffer passed as argument to the function.
func (c *Conn) Read(b []byte) (n int, err error) {
In this case I think it makes sense to apply the change you're proposing (do you want to make a PR? Otherwise I can do it)
Or are you thinking of something else?
from disco.
Related Issues (20)
- Implement in load balancers and reverse proxies
- Document non-PKI ways of using Disco
- Initialize should take []byte for remote keys
- signing keys and Diffie-Hellman keys should be different
- encryptWithAd doesn't care about additional data
- clear secrets as soon as possible
- Security Issues and Breaking Changes Tracker
- Website has no HTTPS (redirect) HOT 1
- Create a merge between Noise and the Disco spec
- need hybrid encryption API
- main website
- balloon hashing for password hashing + password-based KDF
- story around signatures in disco HOT 1
- Christmas Wish: Retrofitting Disco to other sponge constructions HOT 5
- address go report findings
- License clarification HOT 10
- Computing X25519 Secret Keys HOT 11
- move website to a different repo
- "go test" failed HOT 2
- Disco the library needs a spec
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from disco.