Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big revamp #3

Merged
merged 19 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# http://editorconfig.org

root = true

[*.hs]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
end_of_line = lf

[LICENSE]
insert_final_newline = false

[Makefile]
indent_style = tab
3 changes: 3 additions & 0 deletions .ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Sel

secureMain $ pure ()
7 changes: 7 additions & 0 deletions .github/workflows/install-libsodium.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

case "$(uname -s)" in
Linux*) sudo apt install libsodium-dev;;
Darwin*) brew install libsodium;;
esac

33 changes: 33 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Linting

on:
pull_request:
push:
branches: ["main"]

jobs:
fourmolu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: haskell-actions/run-fourmolu@v9
with:
version: "0.12.0.0"
pattern: |
src/**/*.hs
test/**/*.hs

hlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: 'Set up HLint'
uses: haskell-actions/hlint-setup@v2

- name: 'Run HLint'
uses: haskell-actions/hlint-run@v2
with:
path: '["src", "test"]'
fail-on: warning
8 changes: 4 additions & 4 deletions .github/workflows/one-time-password.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ jobs:
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: 'latest'
- name: Freeze
run: cabal freeze
- name: Configure
run: ./.github/workflows/install-libsodium.sh
- name: Cache
uses: actions/cache@v3.3.2
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-cabal-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ runner.os }}-ghc-${{ matrix.ghc }}-
- name: Build
run: cabal build
- name: Test
Expand Down
2 changes: 2 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- ignore: {name: "Eta reduce"}
- ignore: {name: "Use tuple-section" }
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
init: ## Set up git hooks properly - needs calling once
git config core.hooksPath .githooks

deps: ## Install the dependencies of the backend
@cabal build all --only-dependencies

build: ## Build the project in fast mode
@cabal build all

test: ## Build and run the test suite
@cabal test all

clean: ## Remove compilation artifacts
@cabal clean

repl: ## Start a REPL
@cabal repl --repl-options -fobject-code

lint: ## Run the code linter (HLint)
@find src test -name "*.hs" | xargs -P $(PROCS) -I {} hlint --refactor-options="-i" --refactor {}

style: ## Run the code formatter (fourmolu, cabal-fmt)
@cabal-fmt -i one-time-password.cabal
@fourmolu -q --mode inplace test src

help: ## Display this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.* ?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

PROCS := $(shell nproc)

.PHONY: all $(MAKECMDGOALS)

.DEFAULT_GOAL := help
14 changes: 14 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
packages:
./
https://hackage.haskell.org/package/sel-0.0.1.0/candidate/sel-0.0.1.0.tar.gz
https://hackage.haskell.org/package/libsodium-bindings-0.0.1.0/candidate/libsodium-bindings-0.0.1.0.tar.gz

active-repositories: hackage.haskell.org

tests: True

package *
ghc-options: -haddock
documentation: true

test-show-details: direct
11 changes: 11 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
indentation: 2
comma-style: leading # for lists, tuples etc. - can also be 'leading'
import-export-style: leading
record-brace-space: false # rec {x = 1} vs. rec{x = 1}
indent-wheres: true # 'false' means save space by only half-indenting the 'where' keyword
respectful: true # don't be too opinionated about newlines etc.
haddock-style: single-line # '--' vs. '{-'
newlines-between-decls: 1 # number of newlines between top-level declarations
fixities: []
function-arrows: leading
single-constraint-parens: never
130 changes: 79 additions & 51 deletions one-time-password.cabal
Original file line number Diff line number Diff line change
@@ -1,59 +1,87 @@
name: one-time-password
version: 2.0.0
synopsis: HMAC-Based and Time-Based One-Time Passwords

description: Implements HMAC-Based One-Time Password Algorithm as
defined in RFC 4226 and Time-Based One-Time Password
Algorithm as defined in RFC 6238.

license: MIT
license-file: LICENSE
copyright: (c) 2012 Artem Leshchev, 2016 Aleksey Uimanov
author: Artem Leshchev, Aleksey Uimanov
maintainer: The Haskell Cryptography contributors
homepage: https://github.com/haskell-cryptography/one-time-password
bug-reports: https://github.com/haskell-cryptography/one-time-password/issues
category: Cryptography
build-type: Simple
cabal-version: >=1.10

extra-source-files: CHANGELOG.md
, README.md

tested-with:
GHC ==9.2.8 || ==9.4.7 || ==9.6.2
cabal-version: 3.0
name: one-time-password
version: 3.0.0.0
synopsis: HMAC-Based and Time-Based One-Time Passwords
description:
Implements HMAC-Based One-Time Password Algorithm as
defined in RFC 4226 and Time-Based One-Time Password
Algorithm as defined in RFC 6238.

license: MIT
license-file: LICENSE
copyright: (c) 2012 Artem Leshchev, 2016 Aleksey Uimanov
author: Artem Leshchev, Aleksey Uimanov
maintainer: The Haskell Cryptography contributors
homepage: https://github.com/haskell-cryptography/one-time-password
bug-reports:
https://github.com/haskell-cryptography/one-time-password/issues

category: Cryptography
build-type: Simple
extra-source-files:
CHANGELOG.md
README.md

tested-with: GHC ==9.4.8 || ==9.6.3

source-repository head
type: git
location: git://github.com/haskell-cryptography/one-time-password.git

common ghc-options
ghc-options:
-Wall -Wcompat -Widentities -Wincomplete-record-updates
-Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints
-fhide-source-paths -Wno-unused-do-bind -fshow-hole-constraints
-Wno-unticked-promoted-constructors -Werror=unused-imports
-fdicts-strict -fmax-worker-args=16 -fspec-constr-recursive=16
-Wunused-packages

default-language: GHC2021

library
default-language: Haskell2010
hs-source-dirs: src
default-extensions: OverloadedStrings
, ScopedTypeVariables
exposed-modules: Data.OTP
build-depends: base >= 4.16 && < 5
, bytestring
, cereal
, cryptonite
, memory
, time >= 1.1
ghc-options: -Wall
import: ghc-options
hs-source-dirs: src

-- cabal-fmt: expand src/
exposed-modules:
OTP.Commons
OTP.HOTP
OTP.TOTP

build-depends:
, base >=4.16 && <5
, bytestring ^>=0.11
, cereal ^>=0.5
, chronos ^>=1.1
, cryptohash-sha1 ^>=0.11
, network-uri ^>=2.6
, sel
, text ^>=2.0
, text-display ^>=0.0
, torsor ^>=0.1

ghc-options: -Wall

test-suite tests
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: test
ghc-options: -Wall
default-extensions: ExistentialQuantification
, OverloadedStrings
, RankNTypes
main-is: Test.hs
build-depends: base >= 4.16 && < 5
, bytestring
, cryptonite
, one-time-password
, tasty
, tasty-hunit
, time >= 1.1
import: ghc-options
type: exitcode-stdio-1.0
hs-source-dirs: test
default-extensions: OverloadedStrings
main-is: Test.hs
other-modules:
Test.HOTP
Test.TOTP
Test.Utils

build-depends:
, base >=4.16 && <5
, base32 ^>=0.4
, chronos
, one-time-password
, sel
, tasty
, tasty-hunit
, text
, text-display
, torsor
Loading