module Botan.Checksum.CRC
( CRC24(..)
, CRC24Digest(..)
, crc24
, crc24Lazy
, CRC32(..)
, CRC32Digest(..)
, crc32
, crc32Lazy
) where
import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Lazy as Lazy
import qualified Data.Text as Text
import qualified Botan.Hash as Botan
import qualified Botan.Utility as Botan
import Botan.Hash.Class
import Botan.Prelude
data CRC24
newtype instance Digest CRC24 = CRC24Digest
{ Digest CRC24 -> ByteString
getCRC24ByteString :: ByteString }
deriving newtype (Digest CRC24 -> Digest CRC24 -> Bool
(Digest CRC24 -> Digest CRC24 -> Bool)
-> (Digest CRC24 -> Digest CRC24 -> Bool) -> Eq (Digest CRC24)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Digest CRC24 -> Digest CRC24 -> Bool
== :: Digest CRC24 -> Digest CRC24 -> Bool
$c/= :: Digest CRC24 -> Digest CRC24 -> Bool
/= :: Digest CRC24 -> Digest CRC24 -> Bool
Eq, Eq (Digest CRC24)
Eq (Digest CRC24) =>
(Digest CRC24 -> Digest CRC24 -> Ordering)
-> (Digest CRC24 -> Digest CRC24 -> Bool)
-> (Digest CRC24 -> Digest CRC24 -> Bool)
-> (Digest CRC24 -> Digest CRC24 -> Bool)
-> (Digest CRC24 -> Digest CRC24 -> Bool)
-> (Digest CRC24 -> Digest CRC24 -> Digest CRC24)
-> (Digest CRC24 -> Digest CRC24 -> Digest CRC24)
-> Ord (Digest CRC24)
Digest CRC24 -> Digest CRC24 -> Bool
Digest CRC24 -> Digest CRC24 -> Ordering
Digest CRC24 -> Digest CRC24 -> Digest CRC24
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Digest CRC24 -> Digest CRC24 -> Ordering
compare :: Digest CRC24 -> Digest CRC24 -> Ordering
$c< :: Digest CRC24 -> Digest CRC24 -> Bool
< :: Digest CRC24 -> Digest CRC24 -> Bool
$c<= :: Digest CRC24 -> Digest CRC24 -> Bool
<= :: Digest CRC24 -> Digest CRC24 -> Bool
$c> :: Digest CRC24 -> Digest CRC24 -> Bool
> :: Digest CRC24 -> Digest CRC24 -> Bool
$c>= :: Digest CRC24 -> Digest CRC24 -> Bool
>= :: Digest CRC24 -> Digest CRC24 -> Bool
$cmax :: Digest CRC24 -> Digest CRC24 -> Digest CRC24
max :: Digest CRC24 -> Digest CRC24 -> Digest CRC24
$cmin :: Digest CRC24 -> Digest CRC24 -> Digest CRC24
min :: Digest CRC24 -> Digest CRC24 -> Digest CRC24
Ord)
type CRC24Digest = Digest CRC24
instance Show (Digest CRC24) where
show :: Digest CRC24 -> String
show :: Digest CRC24 -> String
show (CRC24Digest ByteString
bytes) = Text -> String
Text.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ ByteString -> HexCase -> Text
Botan.hexEncode ByteString
bytes HexCase
Botan.Lower
instance Hash CRC24 where
hash :: ByteString -> Digest CRC24
hash :: ByteString -> Digest CRC24
hash = ByteString -> Digest CRC24
CRC24Digest (ByteString -> Digest CRC24)
-> (ByteString -> ByteString) -> ByteString -> Digest CRC24
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> ByteString -> ByteString
Botan.hash Hash
Botan.crc24
instance IncrementalHash CRC24 where
hashLazy :: Lazy.ByteString -> Digest CRC24
hashLazy :: ByteString -> Digest CRC24
hashLazy = ByteString -> Digest CRC24
CRC24Digest (ByteString -> Digest CRC24)
-> (ByteString -> ByteString) -> ByteString -> Digest CRC24
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> ByteString -> ByteString
Botan.hashLazy Hash
Botan.crc24
crc24 :: ByteString -> CRC24Digest
crc24 :: ByteString -> Digest CRC24
crc24 = ByteString -> Digest CRC24
forall hash. Hash hash => ByteString -> Digest hash
hash
crc24Lazy :: Lazy.ByteString -> CRC24Digest
crc24Lazy :: ByteString -> Digest CRC24
crc24Lazy = ByteString -> Digest CRC24
forall hash. IncrementalHash hash => ByteString -> Digest hash
hashLazy
data CRC32
newtype instance Digest CRC32 = CRC32Digest
{ Digest CRC32 -> ByteString
getCRC32ByteString :: ByteString }
deriving newtype (Digest CRC32 -> Digest CRC32 -> Bool
(Digest CRC32 -> Digest CRC32 -> Bool)
-> (Digest CRC32 -> Digest CRC32 -> Bool) -> Eq (Digest CRC32)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Digest CRC32 -> Digest CRC32 -> Bool
== :: Digest CRC32 -> Digest CRC32 -> Bool
$c/= :: Digest CRC32 -> Digest CRC32 -> Bool
/= :: Digest CRC32 -> Digest CRC32 -> Bool
Eq, Eq (Digest CRC32)
Eq (Digest CRC32) =>
(Digest CRC32 -> Digest CRC32 -> Ordering)
-> (Digest CRC32 -> Digest CRC32 -> Bool)
-> (Digest CRC32 -> Digest CRC32 -> Bool)
-> (Digest CRC32 -> Digest CRC32 -> Bool)
-> (Digest CRC32 -> Digest CRC32 -> Bool)
-> (Digest CRC32 -> Digest CRC32 -> Digest CRC32)
-> (Digest CRC32 -> Digest CRC32 -> Digest CRC32)
-> Ord (Digest CRC32)
Digest CRC32 -> Digest CRC32 -> Bool
Digest CRC32 -> Digest CRC32 -> Ordering
Digest CRC32 -> Digest CRC32 -> Digest CRC32
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Digest CRC32 -> Digest CRC32 -> Ordering
compare :: Digest CRC32 -> Digest CRC32 -> Ordering
$c< :: Digest CRC32 -> Digest CRC32 -> Bool
< :: Digest CRC32 -> Digest CRC32 -> Bool
$c<= :: Digest CRC32 -> Digest CRC32 -> Bool
<= :: Digest CRC32 -> Digest CRC32 -> Bool
$c> :: Digest CRC32 -> Digest CRC32 -> Bool
> :: Digest CRC32 -> Digest CRC32 -> Bool
$c>= :: Digest CRC32 -> Digest CRC32 -> Bool
>= :: Digest CRC32 -> Digest CRC32 -> Bool
$cmax :: Digest CRC32 -> Digest CRC32 -> Digest CRC32
max :: Digest CRC32 -> Digest CRC32 -> Digest CRC32
$cmin :: Digest CRC32 -> Digest CRC32 -> Digest CRC32
min :: Digest CRC32 -> Digest CRC32 -> Digest CRC32
Ord)
type CRC32Digest = Digest CRC32
instance Show (Digest CRC32) where
show :: Digest CRC32 -> String
show :: Digest CRC32 -> String
show (CRC32Digest ByteString
bytes) = Text -> String
Text.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ ByteString -> HexCase -> Text
Botan.hexEncode ByteString
bytes HexCase
Botan.Lower
instance Hash CRC32 where
hash :: ByteString -> Digest CRC32
hash :: ByteString -> Digest CRC32
hash = ByteString -> Digest CRC32
CRC32Digest (ByteString -> Digest CRC32)
-> (ByteString -> ByteString) -> ByteString -> Digest CRC32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> ByteString -> ByteString
Botan.hash Hash
Botan.crc32
instance IncrementalHash CRC32 where
hashLazy :: Lazy.ByteString -> Digest CRC32
hashLazy :: ByteString -> Digest CRC32
hashLazy = ByteString -> Digest CRC32
CRC32Digest (ByteString -> Digest CRC32)
-> (ByteString -> ByteString) -> ByteString -> Digest CRC32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> ByteString -> ByteString
Botan.hashLazy Hash
Botan.crc32
crc32 :: ByteString -> CRC32Digest
crc32 :: ByteString -> Digest CRC32
crc32 = ByteString -> Digest CRC32
forall hash. Hash hash => ByteString -> Digest hash
hash
crc32Lazy :: Lazy.ByteString -> CRC32Digest
crc32Lazy :: ByteString -> Digest CRC32
crc32Lazy = ByteString -> Digest CRC32
forall hash. IncrementalHash hash => ByteString -> Digest hash
hashLazy