validity-bytestring-0.4.1.1/src/0000755000000000000000000000000013612602711014644 5ustar0000000000000000validity-bytestring-0.4.1.1/src/Data/0000755000000000000000000000000013612602711015515 5ustar0000000000000000validity-bytestring-0.4.1.1/src/Data/Validity/0000755000000000000000000000000013612602711017302 5ustar0000000000000000validity-bytestring-0.4.1.1/src/Data/Validity/ByteString.hs0000644000000000000000000000257713612602711021743 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Validity.ByteString where import Data.Validity import qualified Data.ByteString as SB import qualified Data.ByteString.Internal as SB import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy.Internal as LB import qualified Data.ByteString.Short as Short -- | A 'ByteString' is NOT trivially valid. -- -- The offset and the length both need to be positive. -- Note that the length does not need to be greater than, or equal to, the offset. -- -- TODO there's nothing we can do about the foreign pointer, I think? instance Validity SB.ByteString where validate (SB.PS _ off len) = mconcat [ delve "offset" off , delve "length" len , declare "The offset is positive" $ off >= 0 , declare "The length is positive" $ len >= 0 ] -- | A lazy 'ByteString' is valid according to its chunks. instance Validity LB.ByteString where validate = go 0 where go :: Int -> LB.ByteString -> Validation go _ LB.Empty = valid go i (LB.Chunk sb lb) = mconcat [delve (unwords ["Chunk number", show i]) sb, go (i + 1) lb] -- | Trivially valid -- -- My guess is that short bytestrings are not trivially valid but there is no way to access the internals. instance Validity Short.ShortByteString where validate = trivialValidation validity-bytestring-0.4.1.1/LICENSE0000644000000000000000000000210413620324062015056 0ustar0000000000000000The MIT License (MIT) Copyright (c) 2016-2020 Tom Sydney Kerckhove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. validity-bytestring-0.4.1.1/Setup.hs0000644000000000000000000000005713612602711015513 0ustar0000000000000000import Distribution.Simple main = defaultMain validity-bytestring-0.4.1.1/validity-bytestring.cabal0000644000000000000000000000202213620331574021057 0ustar0000000000000000cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack -- -- hash: 3a60602d0cd285720902eb672df27ae094e261a4816faa49ab29770fe841018e name: validity-bytestring version: 0.4.1.1 synopsis: Validity instances for bytestring description: Please see README.md category: Validity homepage: https://github.com/NorfairKing/validity#readme bug-reports: https://github.com/NorfairKing/validity/issues author: Tom Sydney Kerckhove maintainer: syd@cs-syd.eu copyright: Copyright: (c) 2016-2020 Tom Sydney Kerckhove license: MIT license-file: LICENSE build-type: Simple source-repository head type: git location: https://github.com/NorfairKing/validity library exposed-modules: Data.Validity.ByteString other-modules: Paths_validity_bytestring hs-source-dirs: src build-depends: base >=4.7 && <5 , bytestring , validity >=0.5 default-language: Haskell2010