Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-09 Thread Ian Lance Taylor
On Mon, Oct 9, 2023, 1:59 PM Dean Schulze wrote: > That is mixing concerns (low cohesion), though. At the very least they > need to explain that in the docs. Otherwise that first parameter makes no > sense. > This is a common design pattern in Go. We shouldn't expect that every function that

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-09 Thread Dean Schulze
That is mixing concerns (low cohesion), though. At the very least they need to explain that in the docs. Otherwise that first parameter makes no sense. On Monday, October 9, 2023 at 2:51:11 PM UTC-6 David Anderson wrote: > The first parameter lets you avoid an allocation. If you're

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-09 Thread Dean Schulze
So why even bother with the first parameter then? That looks like a badly designed method signature. On Monday, October 9, 2023 at 8:12:33 AM UTC-6 Axel Wagner wrote: > I get the impression that the thing you are missing is that appending to a > slice does not modify it. That is, `append(s,

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-09 Thread 'Axel Wagner' via golang-nuts
I get the impression that the thing you are missing is that appending to a slice does not modify it. That is, `append(s, x...)` modifies neither the length, nor the content of `s`, you have to type `x = append(s, x...)`. `Seal` (and `Open`) work exactly the same. They append to the `out` parameter

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-09 Thread Jan Mercl
On Mon, Oct 9, 2023 at 3:46 PM Dean Schulze wrote: > If the docs are correct, how do you append to nil? https://go.dev/play/p/WY0Bycj-_Tn -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-09 Thread Bruno Albuquerque
Now including the list and hopefully with less typos. :) append returns a new slice. Appending to nil just means that you are guaranteed that the returned slice will be allocated inside the append function. The same happens if you try to append to a slice that does not have enough capacity to

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-09 Thread Dean Schulze
If the docs are correct, how do you append to nil? That's what the docs say. Take a look at them. Your code example shows the first parameter to Seal() can be nil. So what does that parameter do? How do you append to it? On Sunday, October 8, 2023 at 11:19:13 PM UTC-6 Axel Wagner wrote: >

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-08 Thread 'Axel Wagner' via golang-nuts
For what it's worth, here is an example that demonstrates a typical encryption/decryption roundtrip, perhaps more clearly: https://go.dev/play/p/ZZry8IgTJQ_- The `out` parameter can be used to make this more efficient by using pre-allocated buffers (depending on use case) and there are cases where

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-08 Thread 'Axel Wagner' via golang-nuts
oh I forgot to emphasize: I don't believe the output is *really* ``. That is, I don't believe you can really treat the first N bytes as the encrypted text and decrypt it (say, if you didn't care about the authentication). It's just that you ultimately need to add 16 bytes of extra information to

Re: [go-nuts] The docs for secretbox seem very wrong

2023-10-08 Thread 'Axel Wagner' via golang-nuts
I don't really understand your issue. You call encrypted := secretbox.Seal(nonce[:], []byte(s), , ) That means you pass `nonce[:]` as the `out` argument, `s` as the `message` argument, and the nonce and key and assign the result to `encrypted`. According to the docs of `secretbox`, `Seal` will

[go-nuts] The docs for secretbox seem very wrong

2023-10-08 Thread Dean Schulze
The docs for secretbox.Seal say: func Seal(out, message []byte, nonce *[24]byte, key *[32]byte) []byte Seal appends an encrypted and authenticated copy of message to out, which must not overlap message. The key and nonce pair must be