Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

crypto functions should accept buffers as arguments #1393

Closed
bnoordhuis opened this issue Jul 24, 2011 · 17 comments
Closed

crypto functions should accept buffers as arguments #1393

bnoordhuis opened this issue Jul 24, 2011 · 17 comments
Labels

Comments

@bnoordhuis
Copy link
Member

#1027 fixes this for HMAC.

Maybe deprecate string arguments altogether. It's the most widely misunderstood part of node if bug reports, the ML and IRC are anything to go by.

CC @pquerna

@baudehlo
Copy link

baudehlo commented Oct 3, 2011

They also need to return buffers. e.g. hash.digest() should return a Buffer and if you want to decode it to hex then that's optional.

@sh1mmer
Copy link

sh1mmer commented Nov 3, 2011

@bnoordhuis @pquerna is this still relevent?

Is there a list of crypto functions that don't support Buffers?

@sh1mmer
Copy link

sh1mmer commented Nov 3, 2011

I tried createHash and it took Buffers just fine on a sha1 Hash object.

@betamos
Copy link

betamos commented Nov 23, 2011

I asked a similar question on Stack Overflow. Subscribing.

@net147
Copy link

net147 commented Jan 26, 2012

Similar problem with the signer.sign and verifier.verify. I tried to use signature in a buffer with verifier.verify and it didn't work. It worked when I converted the buffer to a hex string and passed it into verifier.verify as hex though.

@thiagoarrais
Copy link

I started to fix this at https://github.com/thiagoarrais/node/tree/crypto-buffer

My initial plan is to fix all the binary string arguments then get into the return values. I'll use the current convention of a request for null encoding returning a buffer.

This is my first patch for node and I would really appreciate if someone could take a look at this to help me make it easier to be accepted and merged back.

@bnoordhuis
Copy link
Member Author

@thiagoarrais: It's easiest if you submit it as a pull request. One thing I noticed is long lines, we have a 80 characters limit.

@thiagoarrais
Copy link

I'll take a look at the 80 char limit. I didn't want to make it a pull request while it is too raw, but can do that if you guys prefer it that way.

@thiagoarrais
Copy link

Please take a look at the pull request. I think with these last commits I've finished converting the arguments (inputs). I have also updated the docs and will start working on the return values (outputs) next.

But I think we should consider removing encoded strings altogether. There certainly are backwards compatibility issues, but that's what 0.x is for, isn't it? Buffers have been around and recommended for quite some time now after all.

@thiagoarrais
Copy link

Any updates here?

@isaacs
Copy link

isaacs commented Jun 22, 2012

@bnoordhuis This (at least partly) landed in 0.8, correct?

@bnoordhuis
Copy link
Member Author

This (at least partly) landed in 0.8, correct?

Yes, commit 900196e.

@thiagoarrais
Copy link

As far as I can tell, this updates only inputs to cypher/decypher. Outputs should be able to be buffers too and there are other functions (sign and verify, for example) that still need to be adapted. I am in a hurry and looking this commit only. Maybe I'm wrong and everything is already in place in 0.8.

I don't think my pull request applies cleanly anymore, but I can port it to the current codebase if there is interest.

@isaacs
Copy link

isaacs commented Jun 23, 2012

@thiagoarrais Yes, please feel free to rebase to master and resubmit. We would most likely take a pull req for this on v0.9 if it didn't break anything else, but it's too late to get into v0.8.

@thiagoarrais
Copy link

@isaacs done! The old patch applied almost without any modification. I just squashed the old commits together and adjusted the tests.

Please take this as a conversation starter and let me know if there is anything that needs to be changed.

@thiagoarrais
Copy link

any updates here?

@bnoordhuis
Copy link
Member Author

Closing. This has been fixed in v0.10.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants