Remove implicit converters

This commit is contained in:
Giovanni Petrantoni 2020-02-17 00:54:53 +09:00 committed by Dmitriy Ryajov
parent f039853a19
commit e0e371994c
3 changed files with 9 additions and 9 deletions

View File

@ -28,15 +28,15 @@ type
ChaChaPolyNonce* = array[ChaChaPolyNonceSize, byte] ChaChaPolyNonce* = array[ChaChaPolyNonceSize, byte]
ChaChaPolyTag* = array[ChaChaPolyTagSize, byte] ChaChaPolyTag* = array[ChaChaPolyTagSize, byte]
converter toChaChaPolyKey*(s: seq[byte]): ChaChaPolyKey = proc intoChaChaPolyKey*(s: seq[byte]): ChaChaPolyKey =
assert s.len == ChaChaPolyKeySize assert s.len == ChaChaPolyKeySize
copyMem(addr result[0], unsafeaddr s[0], ChaChaPolyKeySize) copyMem(addr result[0], unsafeaddr s[0], ChaChaPolyKeySize)
converter toChaChaPolyNonce*(s: seq[byte]): ChaChaPolyNonce = proc intoChaChaPolyNonce*(s: seq[byte]): ChaChaPolyNonce =
assert s.len == ChaChaPolyNonceSize assert s.len == ChaChaPolyNonceSize
copyMem(addr result[0], unsafeaddr s[0], ChaChaPolyNonceSize) copyMem(addr result[0], unsafeaddr s[0], ChaChaPolyNonceSize)
converter toChaChaPolyTag*(s: seq[byte]): ChaChaPolyTag = proc intoChaChaPolyTag*(s: seq[byte]): ChaChaPolyTag =
assert s.len == ChaChaPolyTagSize assert s.len == ChaChaPolyTagSize
copyMem(addr result[0], unsafeaddr s[0], ChaChaPolyTagSize) copyMem(addr result[0], unsafeaddr s[0], ChaChaPolyTagSize)

View File

@ -25,7 +25,7 @@ type
Curve25519Key* = array[Curve25519KeySize, byte] Curve25519Key* = array[Curve25519KeySize, byte]
pcuchar = ptr cuchar pcuchar = ptr cuchar
converter toCurve25519Key*(s: seq[byte]): Curve25519Key = proc intoCurve25519Key*(s: seq[byte]): Curve25519Key =
assert s.len == Curve25519KeySize assert s.len == Curve25519KeySize
copyMem(addr result[0], unsafeaddr s[0], Curve25519KeySize) copyMem(addr result[0], unsafeaddr s[0], Curve25519KeySize)

View File

@ -499,7 +499,7 @@ suite "Key interface test suite":
bearIn = fromHex("E6DB6867583030DB3594C1A424B15F7C726624EC26B3353B10A903A6D0AB1C4C") bearIn = fromHex("E6DB6867583030DB3594C1A424B15F7C726624EC26B3353B10A903A6D0AB1C4C")
bearOut = fromHex("C3DA55379DE9C6908E94EA4DF28D084F32ECCF03491C71F754B4075577A28552") bearOut = fromHex("C3DA55379DE9C6908E94EA4DF28D084F32ECCF03491C71F754B4075577A28552")
Curve25519.mul(res, bearIn, bearOp) Curve25519.mul(res, bearIn.intoCurve25519Key, bearOp.intoCurve25519Key)
check res == bearOut check res == bearOut
# from https://github.com/golang/crypto/blob/1d94cc7ab1c630336ab82ccb9c9cda72a875c382/curve25519/vectors_test.go#L26 # from https://github.com/golang/crypto/blob/1d94cc7ab1c630336ab82ccb9c9cda72a875c382/curve25519/vectors_test.go#L26
@ -513,13 +513,13 @@ suite "Key interface test suite":
check public1.toHex == public1Test.toHex check public1.toHex == public1Test.toHex
# RFC vectors # RFC vectors
private1 = fromHex("a8abababababababababababababababababababababababababababababab6b") private1 = fromHex("a8abababababababababababababababababababababababababababababab6b").intoCurve25519Key
check private1.public().toHex == "E3712D851A0E5D79B831C5E34AB22B41A198171DE209B8B8FACA23A11C624859" check private1.public().toHex == "E3712D851A0E5D79B831C5E34AB22B41A198171DE209B8B8FACA23A11C624859"
private1 = fromHex("c8cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd4d") private1 = fromHex("c8cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd4d").intoCurve25519Key
check private1.public().toHex == "B5BEA823D9C9FF576091C54B7C596C0AE296884F0E150290E88455D7FBA6126F" check private1.public().toHex == "B5BEA823D9C9FF576091C54B7C596C0AE296884F0E150290E88455D7FBA6126F"
private1 = fromHex("77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a") private1 = fromHex("77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a").intoCurve25519Key
var var
private2 = fromHex("5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb") private2 = fromHex("5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb").intoCurve25519Key
p1Pub = private1.public() p1Pub = private1.public()
p2Pub = private2.public() p2Pub = private2.public()
check p1Pub.toHex == "8520F0098930A754748B7DDCB43EF75A0DBF3A0D26381AF4EBA4A98EAA9B4E6A" check p1Pub.toHex == "8520F0098930A754748B7DDCB43EF75A0DBF3A0D26381AF4EBA4A98EAA9B4E6A"