{-# language CPP #-}
module System.Nix.Internal.Signature
( Signature
, NarSignature(..)
)
where
import qualified Data.ByteString as Bytes
import Crypto.Saltine.Core.Sign ( PublicKey )
import Crypto.Saltine.Class ( IsEncoding(..) )
#if MIN_VERSION_saltine(0,2,0)
import qualified Crypto.Saltine.Internal.Sign as NaClSizes
#else
import qualified Crypto.Saltine.Internal.ByteSizes as NaClSizes
#endif
newtype Signature = Signature ByteString
deriving (Signature -> Signature -> Bool
(Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool) -> Eq Signature
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Signature -> Signature -> Bool
$c/= :: Signature -> Signature -> Bool
== :: Signature -> Signature -> Bool
$c== :: Signature -> Signature -> Bool
Eq, Eq Signature
Eq Signature
-> (Signature -> Signature -> Ordering)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Signature)
-> (Signature -> Signature -> Signature)
-> Ord Signature
Signature -> Signature -> Bool
Signature -> Signature -> Ordering
Signature -> Signature -> Signature
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
min :: Signature -> Signature -> Signature
$cmin :: Signature -> Signature -> Signature
max :: Signature -> Signature -> Signature
$cmax :: Signature -> Signature -> Signature
>= :: Signature -> Signature -> Bool
$c>= :: Signature -> Signature -> Bool
> :: Signature -> Signature -> Bool
$c> :: Signature -> Signature -> Bool
<= :: Signature -> Signature -> Bool
$c<= :: Signature -> Signature -> Bool
< :: Signature -> Signature -> Bool
$c< :: Signature -> Signature -> Bool
compare :: Signature -> Signature -> Ordering
$ccompare :: Signature -> Signature -> Ordering
$cp1Ord :: Eq Signature
Ord)
instance IsEncoding Signature where
decode :: ByteString -> Maybe Signature
decode ByteString
s
#if MIN_VERSION_saltine(0,2,0)
| Bytes.length s == NaClSizes.sign_bytes = Just $ Signature s
#else
| ByteString -> Int
Bytes.length ByteString
s Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
NaClSizes.sign = Signature -> Maybe Signature
forall a. a -> Maybe a
Just (Signature -> Maybe Signature) -> Signature -> Maybe Signature
forall a b. (a -> b) -> a -> b
$ ByteString -> Signature
Signature ByteString
s
#endif
| Bool
otherwise = Maybe Signature
forall a. Maybe a
Nothing
encode :: Signature -> ByteString
encode = Signature -> ByteString
coerce
data NarSignature = NarSignature
{
NarSignature -> PublicKey
publicKey :: PublicKey
,
NarSignature -> Signature
sig :: Signature
}
deriving (NarSignature -> NarSignature -> Bool
(NarSignature -> NarSignature -> Bool)
-> (NarSignature -> NarSignature -> Bool) -> Eq NarSignature
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NarSignature -> NarSignature -> Bool
$c/= :: NarSignature -> NarSignature -> Bool
== :: NarSignature -> NarSignature -> Bool
$c== :: NarSignature -> NarSignature -> Bool
Eq, Eq NarSignature
Eq NarSignature
-> (NarSignature -> NarSignature -> Ordering)
-> (NarSignature -> NarSignature -> Bool)
-> (NarSignature -> NarSignature -> Bool)
-> (NarSignature -> NarSignature -> Bool)
-> (NarSignature -> NarSignature -> Bool)
-> (NarSignature -> NarSignature -> NarSignature)
-> (NarSignature -> NarSignature -> NarSignature)
-> Ord NarSignature
NarSignature -> NarSignature -> Bool
NarSignature -> NarSignature -> Ordering
NarSignature -> NarSignature -> NarSignature
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
min :: NarSignature -> NarSignature -> NarSignature
$cmin :: NarSignature -> NarSignature -> NarSignature
max :: NarSignature -> NarSignature -> NarSignature
$cmax :: NarSignature -> NarSignature -> NarSignature
>= :: NarSignature -> NarSignature -> Bool
$c>= :: NarSignature -> NarSignature -> Bool
> :: NarSignature -> NarSignature -> Bool
$c> :: NarSignature -> NarSignature -> Bool
<= :: NarSignature -> NarSignature -> Bool
$c<= :: NarSignature -> NarSignature -> Bool
< :: NarSignature -> NarSignature -> Bool
$c< :: NarSignature -> NarSignature -> Bool
compare :: NarSignature -> NarSignature -> Ordering
$ccompare :: NarSignature -> NarSignature -> Ordering
$cp1Ord :: Eq NarSignature
Ord)