Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor bits/bytes conversion #45

Merged
merged 1 commit into from
Apr 24, 2023
Merged

Conversation

oleiade
Copy link
Member

@oleiade oleiade commented Apr 14, 2023

This PR address #36 and introduces two new type aliases: bitLength and byteLength helping make conversion from bytes length to bits and vice versa, more explicit, readable, and less error prone.

closes #36

@oleiade oleiade requested review from mstoykov and imiric April 14, 2023 09:53
@oleiade oleiade force-pushed the refactor/bits-bytes-conversion branch 2 times, most recently from 3b4282e to 2b3ed69 Compare April 14, 2023 12:17
webcrypto/aes.go Outdated Show resolved Hide resolved
@oleiade oleiade force-pushed the refactor/bits-bytes-conversion branch from 2b3ed69 to 4c72387 Compare April 14, 2023 13:10
webcrypto/types.go Outdated Show resolved Hide resolved
@oleiade oleiade force-pushed the refactor/bits-bytes-conversion branch from 4c72387 to fc4f3d6 Compare April 19, 2023 08:37
webcrypto/aes.go Outdated Show resolved Hide resolved
@@ -86,7 +86,7 @@ func (akgp *AESKeyGenParams) GenerateKey(
key.Type = SecretCryptoKeyType
key.Algorithm = AESKeyAlgorithm{
Algorithm: akgp.Algorithm,
Length: akgp.Length,
Length: int64(akgp.Length),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change that Length field as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the best of my knowledge, unfortunately not. The reason is that as soon as you use bitLength as a type for the Length attribute the AesKeyAlgorithm type, then its value is treated as an object by Goja, not a number, which leads the test suite to fail. I have noticed this behavior before, hence some of the type mappings that exist are actual type aliases type mytype = string. However, in that case, we can't really do that, as we wouldn't be able to have methods on type aliases.

webcrypto/hmac.go Outdated Show resolved Hide resolved
webcrypto/hmac.go Outdated Show resolved Hide resolved
@oleiade oleiade force-pushed the refactor/bits-bytes-conversion branch from fc4f3d6 to b96901b Compare April 24, 2023 09:59
@oleiade oleiade merged commit c929275 into main Apr 24, 2023
3 checks passed
@oleiade oleiade deleted the refactor/bits-bytes-conversion branch April 24, 2023 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I am not really happy with this *8 and then /8 in places.
3 participants