jedisct1 / libsodium-doc

Gitbook documentation for libsodium
https://libsodium.org
ISC License
166 stars 159 forks source link

Clarify secretstream example code comments. #169

Closed matthewmummert5 closed 1 year ago

matthewmummert5 commented 1 year ago

I looked pretty hard at the example file encryption code in the secretstream documentation for a while. I think that the comment in this statement is backwards:

if (tag == crypto_secretstream_xchacha20poly1305_TAG_FINAL && ! eof) {
    goto ret; /* premature end (end of file reached before the end of the stream) */
}

I think what it should say is End of stream reached before the end of the file because ! eof will be true if we have not reached the end of the file.

I also added a check for if the file ends before the end of the stream to the example code.

Feel free to add suggestions or correct me if I'm wrong.

jedisct1 commented 1 year ago

Thanks a lot!

Indeed, this example was wrong.