# std.crypto.tls.Client: fix the read function · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/940d368e7ea95d2bb8185e71af3d1ec0328917dc)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 940d368e7ea95d2bb8185e71af3d1ec0328917dc

Requested commit: 940d368e7ea95d2bb8185e71af3d1ec0328917dc

Commit: 940d368e7ea95d2bb8185e71af3d1ec0328917dc

Tree: a2338ec0d47f74c0badfe0a22d2e77e5044e3082

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
std.crypto.tls.Client: fix the read function

The read function has been renamed to readAdvanced since it has slightly
different semantics than typical read functions, specifically regarding
the end-of-file. A higher level read function is implemented on top.

Now, API users may pass small buffers to the read function and
everything will work fine. This is done by re-decrypting the same
ciphertext record with each call to read() until the record is finished
being transmitted.

If the buffer supplied to read() is large enough, then any given
ciphertext record will only be decrypted once, since it decrypts
directly to the read() buffer and therefore does not need any memcpy. On
the other hand, if the buffer supplied to read() is small, then the
ciphertext is decrypted into a stack buffer, a subset is copied to the
read() buffer, and then the entire ciphertext record is saved for the
next call to read().

```

## Parents

- [21ab99174eabc9ae8efa2b19890d9cab51773b35](https://git.cafe/gitcafe/zig/commit/21ab99174eabc9ae8efa2b19890d9cab51773b35?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/940d368e7ea95d2bb8185e71af3d1ec0328917dc?format=markdown)
