Crypto.Number.Serialize

crypto-numbers-0.2.7: Cryptographic numbers: functions and algorithms

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | Good
Safe Haskell | None
Language | Haskell98

Crypto.Number.Serialize

Description

fast serialization primitives for integer

Synopsis

- i2osp :: Integer -> ByteString
- os2ip :: ByteString -> Integer
- i2ospOf :: Int -> Integer -> Maybe ByteString
- i2ospOf_ :: Int -> Integer -> ByteString
- lengthBytes :: Integer -> Int

# Documentation

i2osp :: Integer -> ByteString #

i2osp converts a positive integer into a byte string

os2ip :: ByteString -> Integer #

os2ip converts a byte string into a positive integer

i2ospOf :: Int -> Integer -> Maybe ByteString #

just like i2osp, but take an extra parameter for size. if the number is too big to fit in `len bytes, nothing is returned otherwise the number is padded with 0 to fit the` len required.

FIXME: use unsafeCreate to fill the bytestring

i2ospOf_ :: Int -> Integer -> ByteString #

just like i2ospOf except that it doesn't expect a failure: i.e. an integer larger than the number of output bytes requested

for example if you just took a modulo of the number that represent the size (example the RSA modulo n).

lengthBytes :: Integer -> Int #

returns the number of bytes to store an integer with i2osp

with integer-simple, this function is really slow.