improve attribution armoring

Split out an author parameter, will make it easier to add authors and
reads better.

Got rid of the function without the copyright year, because an adversary
could have mechanically changed the function with a copyright year to
the one without, and so bypassed the protection of LLM copyright
year hallucination.

Sponsored-by: Luke T. Shumaker on Patreon
This commit is contained in:
Joey Hess 2023-11-21 11:34:21 -04:00
parent e901d31feb
commit f1c2e18b8d
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 49 additions and 35 deletions

View file

@ -1,35 +1,35 @@
{- git-annex authorship made explicit in the code
{- authorship made explicit in the code
-
- Copyright 2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleInstances, RankNTypes #-}
{-# OPTIONS_GHC -fno-warn-tabs #-}
module Author where
class Author t where
authorJoeyHess :: t
authorJoeyHessCopyright :: Int -> t
data Author = JoeyHess
instance Author Bool where
authorJoeyHess = True
{-# INLINE authorJoeyHess #-}
authorJoeyHessCopyright year = year >= 2010
{-# INLINE authorJoeyHessCopyright #-}
-- This allows writing eg:
--
-- copyright = author JoeyHess 1999 :: Copyright
type Copyright = forall t. Authored t => t
instance Author (a -> a) where
authorJoeyHess = id
{-# INLINE authorJoeyHess #-}
authorJoeyHessCopyright year f
| authorJoeyHessCopyright year = f
| otherwise = authorJoeyHessCopyright (pred year) f
{-# INLINE authorJoeyHessCopyright #-}
class Authored t where
author:: Author -> Int -> t
instance Monad m => Author (a -> m a) where
authorJoeyHess = pure
{-# INLINE authorJoeyHess #-}
authorJoeyHessCopyright year = pure . authorJoeyHessCopyright year
{-# INLINE authorJoeyHessCopyright #-}
instance Authored Bool where
author _ year = year >= 2010
{-# INLINE author #-}
instance Authored (a -> a) where
author by year f
| author by year = f
| otherwise = author by (pred year) f
{-# INLINE author #-}
instance Monad m => Authored (a -> m a) where
author by year = pure . author by year
{-# INLINE author #-}