Skip to content

Chunking with Streams #171

@willchan

Description

@willchan

I was chatting with jyasskin and agl (explicitly chose not to cc them on this thread, although maybe I should have) over dinner today, talking about new C++ standard library proposals around transforms, which were very similar to streams. One thing stuck out in particular to me, where partial writes/reads matter for chunked protocols. Looking at the TLS record format, you can see that there's a MAC on the payload. The standard way to do this with a streaming interface is to, on each write invocation, slap on the MAC. This would be implicit to the interface, and not explicit anywhere. You'd just have to know that a stream that wrapped a SSL connection did this. Which is fine. On the read side, without an internal buffer in the stream, you can't read fewer bytes than are contained in the payload of a TLS record, since you can't partially read bytes until you verify the integrity of that data via the MAC, which is appended to the record.

Of course, this breaks some of the compositional abstraction with streams. You'd like to just pipe and compose streams willy nilly without thinking about this, but if you actually do care about the performance (and to a lesser degree, correctness, since you may break functionality if the internal buffer is too small to absorb an entire TLS record's payload + MAC), then you will need to think about this at some point.

Just some food for thought. I am writing it up here for posterity's sake. Feel free to close.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions