Compare commits
No commits in common. "main" and "gh-pages" have entirely different histories.
133 changed files with 11697 additions and 9137 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB |
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
|
|
@ -1,3 +0,0 @@
|
||||||
# These are supported funding model platforms
|
|
||||||
|
|
||||||
github: [snider]
|
|
||||||
44
.github/workflows/go.yml
vendored
44
.github/workflows/go.yml
vendored
|
|
@ -1,44 +0,0 @@
|
||||||
name: Go
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version-file: 'go.work'
|
|
||||||
|
|
||||||
- name: Setup Task
|
|
||||||
uses: arduino/setup-task@v1
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: go build -v ./...
|
|
||||||
|
|
||||||
- name: Vet
|
|
||||||
run: go vet ./...
|
|
||||||
|
|
||||||
- name: Test (race + coverage)
|
|
||||||
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
|
||||||
|
|
||||||
- name: Fuzz (10s)
|
|
||||||
run: go test -run=Fuzz -fuzz=Fuzz -fuzztime=10s ./pkg/trix
|
|
||||||
|
|
||||||
- name: Upload coverage reports to Codecov
|
|
||||||
uses: codecov/codecov-action@v5
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
|
||||||
|
|
||||||
- name: Upload coverage report
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: coverage-report
|
|
||||||
path: coverage.out
|
|
||||||
17
.github/workflows/mkdocs.yml
vendored
17
.github/workflows/mkdocs.yml
vendored
|
|
@ -1,17 +0,0 @@
|
||||||
name: Publish Docs
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: actions/setup-python@v3
|
|
||||||
with:
|
|
||||||
python-version: '3.x'
|
|
||||||
- run: |
|
|
||||||
pip install mkdocs-material
|
|
||||||
- run: |
|
|
||||||
cd docs && mkdocs gh-deploy --force --clean --verbose
|
|
||||||
14
.gitignore
vendored
14
.gitignore
vendored
|
|
@ -1,14 +0,0 @@
|
||||||
node_modules
|
|
||||||
package-lock.json
|
|
||||||
.idea
|
|
||||||
covdata/
|
|
||||||
merged_covdata/
|
|
||||||
coverage.txt
|
|
||||||
coverage.html
|
|
||||||
coverage.out
|
|
||||||
test.*
|
|
||||||
# Build artifacts
|
|
||||||
/dist/
|
|
||||||
/site/
|
|
||||||
# macOS
|
|
||||||
.DS_Store
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
# .goreleaser.yml
|
|
||||||
before:
|
|
||||||
hooks:
|
|
||||||
- go mod tidy
|
|
||||||
builds:
|
|
||||||
- env:
|
|
||||||
- CGO_ENABLED=0
|
|
||||||
goos:
|
|
||||||
- linux
|
|
||||||
- windows
|
|
||||||
- darwin
|
|
||||||
main: ./cmd/trix
|
|
||||||
binary: trix
|
|
||||||
id: "trix"
|
|
||||||
|
|
||||||
archives:
|
|
||||||
- replacements:
|
|
||||||
darwin: Darwin
|
|
||||||
linux: Linux
|
|
||||||
windows: Windows
|
|
||||||
386: i386
|
|
||||||
amd64: x86_64
|
|
||||||
|
|
||||||
checksum:
|
|
||||||
name_template: 'checksums.txt'
|
|
||||||
|
|
||||||
snapshot:
|
|
||||||
name_template: "{{ incpatch .Version }}-next"
|
|
||||||
|
|
||||||
changelog:
|
|
||||||
sort: asc
|
|
||||||
filters:
|
|
||||||
exclude:
|
|
||||||
- '^docs:'
|
|
||||||
- '^test:'
|
|
||||||
0
.nojekyll
Normal file
0
.nojekyll
Normal file
|
|
@ -1,5 +0,0 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="false" name="Test" type="DenoConfigurationType" inputPath="$PROJECT_DIR$" programParameters="test">
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
457
404.html
Normal file
457
404.html
Normal file
|
|
@ -0,0 +1,457 @@
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en" class="no-js">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="icon" href="/assets/images/favicon.png">
|
||||||
|
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.23">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<title>Enchantrix</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/assets/stylesheets/main.84d31ad4.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||||
|
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>__md_scope=new URL("/",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<body dir="ltr">
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||||
|
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||||
|
<label class="md-overlay" for="__drawer"></label>
|
||||||
|
<div data-md-component="skip">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div data-md-component="announce">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<header class="md-header md-header--shadow" data-md-component="header">
|
||||||
|
<nav class="md-header__inner md-grid" aria-label="Header">
|
||||||
|
<a href="/." title="Enchantrix" class="md-header__button md-logo" aria-label="Enchantrix" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
<label class="md-header__button md-icon" for="__drawer">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-header__title" data-md-component="header-title">
|
||||||
|
<div class="md-header__ellipsis">
|
||||||
|
<div class="md-header__topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Enchantrix
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="md-header__topic" data-md-component="header-topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" for="__search">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
|
<label class="md-search__overlay" for="__search"></label>
|
||||||
|
<div class="md-search__inner" role="search">
|
||||||
|
<form class="md-search__form" name="search">
|
||||||
|
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
|
||||||
|
<label class="md-search__icon md-icon" for="__search">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
|
||||||
|
</label>
|
||||||
|
<nav class="md-search__options" aria-label="Search">
|
||||||
|
|
||||||
|
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<div class="md-search__output">
|
||||||
|
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
|
||||||
|
<div class="md-search-result" data-md-component="search-result">
|
||||||
|
<div class="md-search-result__meta">
|
||||||
|
Initializing search
|
||||||
|
</div>
|
||||||
|
<ol class="md-search-result__list" role="presentation"></ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="md-container" data-md-component="container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<main class="md-main" data-md-component="main">
|
||||||
|
<div class="md-main__inner md-grid">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
|
||||||
|
<label class="md-nav__title" for="__drawer">
|
||||||
|
<a href="/." title="Enchantrix" class="md-nav__button md-logo" aria-label="Enchantrix" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
Enchantrix
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="/." class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Home
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="/trix_format/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix File Format
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--nested">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Examples
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
|
||||||
|
<label class="md-nav__title" for="__nav_3">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Examples
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="/trix_and_sigils/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix & Sigil Chaining
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="/hashing/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Hashing
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="/checksums/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Checksums
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="/rsa/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
RSA
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="/standalone_sigils/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Standalone Sigils
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-content" data-md-component="content">
|
||||||
|
<article class="md-content__inner md-typeset">
|
||||||
|
|
||||||
|
<h1>404 - Not found</h1>
|
||||||
|
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="md-footer">
|
||||||
|
|
||||||
|
<div class="md-footer-meta md-typeset">
|
||||||
|
<div class="md-footer-meta__inner md-grid">
|
||||||
|
<div class="md-copyright">
|
||||||
|
|
||||||
|
|
||||||
|
Made with
|
||||||
|
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||||
|
Material for MkDocs
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="md-dialog" data-md-component="dialog">
|
||||||
|
<div class="md-dialog__inner md-typeset"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script id="__config" type="application/json">{"base": "/", "features": [], "search": "/assets/javascripts/workers/search.973d3a69.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="/assets/javascripts/bundle.f55a23d4.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
85
CLAUDE.md
85
CLAUDE.md
|
|
@ -1,85 +0,0 @@
|
||||||
# CLAUDE.md
|
|
||||||
|
|
||||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
||||||
|
|
||||||
## Build and Test Commands
|
|
||||||
|
|
||||||
```shell
|
|
||||||
# Run all tests with coverage
|
|
||||||
go test -v -coverprofile=coverage.out ./...
|
|
||||||
|
|
||||||
# Run a single test
|
|
||||||
go test -v -run TestName ./pkg/enchantrix
|
|
||||||
|
|
||||||
# Run tests with race detection (as CI does)
|
|
||||||
go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
|
||||||
|
|
||||||
# Run fuzz tests (CI runs 10s)
|
|
||||||
go test -run=Fuzz -fuzz=Fuzz -fuzztime=10s ./pkg/trix
|
|
||||||
|
|
||||||
# Build
|
|
||||||
go build -v ./...
|
|
||||||
|
|
||||||
# Vet
|
|
||||||
go vet ./...
|
|
||||||
|
|
||||||
# Format
|
|
||||||
go fmt ./...
|
|
||||||
```
|
|
||||||
|
|
||||||
If Task is installed, these are available:
|
|
||||||
- `task test` - Run tests with coverage
|
|
||||||
- `task build` - Build project
|
|
||||||
- `task fmt` - Format code
|
|
||||||
- `task vet` - Run go vet
|
|
||||||
|
|
||||||
## Architecture
|
|
||||||
|
|
||||||
Enchantrix is an encryption library with a custom `.trix` file format and CLI tool.
|
|
||||||
|
|
||||||
### Core Packages
|
|
||||||
|
|
||||||
**pkg/enchantrix** - Core transformation framework
|
|
||||||
- `Sigil` interface: defines `In(data)` and `Out(data)` for reversible/irreversible transforms
|
|
||||||
- `Transmute()`: applies a chain of sigils to data
|
|
||||||
- Built-in sigils: `reverse`, `hex`, `base64`, `gzip`, `json`, `json-indent`
|
|
||||||
- Hash sigils: `md4`, `md5`, `sha1`, `sha224`, `sha256`, `sha384`, `sha512`, `ripemd160`, `sha3-*`, `sha512-*`, `blake2s-256`, `blake2b-*`
|
|
||||||
- `NewSigil(name)`: factory function to create sigils by string name
|
|
||||||
- `ChaChaPolySigil`: encryption sigil using XChaCha20-Poly1305 with pre-obfuscation layer
|
|
||||||
|
|
||||||
**pkg/trix** - Binary file format (.trix)
|
|
||||||
- Format: `[4-byte magic][1-byte version][4-byte header len][JSON header][payload]`
|
|
||||||
- `Encode()`: serializes Trix struct to binary
|
|
||||||
- `Decode()`: deserializes binary to Trix struct
|
|
||||||
- `Pack()`/`Unpack()`: apply/reverse sigils on payload
|
|
||||||
- Supports optional checksums via `ChecksumAlgo` field
|
|
||||||
|
|
||||||
**pkg/crypt** - Cryptographic services facade
|
|
||||||
- `Service`: aggregates hashing, checksums, RSA, and PGP operations
|
|
||||||
- Hash types: `lthn` (custom), `sha512`, `sha256`, `sha1`, `md5`
|
|
||||||
- Checksums: `Luhn()`, `Fletcher16/32/64()`
|
|
||||||
- RSA: key generation, encrypt/decrypt via `pkg/crypt/std/rsa`
|
|
||||||
- PGP: key generation, encrypt/decrypt, sign/verify, symmetric encrypt via `pkg/crypt/std/pgp`
|
|
||||||
|
|
||||||
**cmd/trix** - CLI tool (Cobra-based)
|
|
||||||
- `trix encode --magic XXXX --output file [sigils...]`
|
|
||||||
- `trix decode --magic XXXX --output file [sigils...]`
|
|
||||||
- `trix hash [algorithm]`
|
|
||||||
- `trix [sigil]` - apply any sigil directly
|
|
||||||
|
|
||||||
### Key Design Patterns
|
|
||||||
|
|
||||||
1. **Sigil Chain**: Transformations are composable. Encoding chains sigils in order; decoding reverses.
|
|
||||||
2. **Pre-Obfuscation**: `ChaChaPolySigil` applies XOR or shuffle-mask obfuscation before encryption so raw plaintext never goes directly to CPU encryption routines.
|
|
||||||
3. **Streaming Support**: `Encode()`/`Decode()` accept optional `io.Writer`/`io.Reader` for streaming.
|
|
||||||
|
|
||||||
## Testing Conventions
|
|
||||||
|
|
||||||
- Tests use `testify/assert` and `testify/require`
|
|
||||||
- Test files follow `*_test.go` pattern adjacent to implementation
|
|
||||||
- `examples_test.go` files contain example functions for godoc
|
|
||||||
- Fuzz tests exist in `pkg/trix` (`go test -fuzz`)
|
|
||||||
|
|
||||||
## Go Version
|
|
||||||
|
|
||||||
Minimum Go 1.25. Uses `go.work` for workspace management.
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
To be clear, even morally, I'm not responsible for anyone using my code like an asshat; don't put your evil on me.
|
|
||||||
287
LICENCE
287
LICENCE
|
|
@ -1,287 +0,0 @@
|
||||||
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
|
||||||
EUPL © the European Union 2007, 2016
|
|
||||||
|
|
||||||
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
|
|
||||||
below) which is provided under the terms of this Licence. Any use of the Work,
|
|
||||||
other than as authorised under this Licence is prohibited (to the extent such
|
|
||||||
use is covered by a right of the copyright holder of the Work).
|
|
||||||
|
|
||||||
The Work is provided under the terms of this Licence when the Licensor (as
|
|
||||||
defined below) has placed the following notice immediately following the
|
|
||||||
copyright notice for the Work:
|
|
||||||
|
|
||||||
Licensed under the EUPL
|
|
||||||
|
|
||||||
or has expressed by any other means his willingness to license under the EUPL.
|
|
||||||
|
|
||||||
1. Definitions
|
|
||||||
|
|
||||||
In this Licence, the following terms have the following meaning:
|
|
||||||
|
|
||||||
- ‘The Licence’: this Licence.
|
|
||||||
|
|
||||||
- ‘The Original Work’: the work or software distributed or communicated by the
|
|
||||||
Licensor under this Licence, available as Source Code and also as Executable
|
|
||||||
Code as the case may be.
|
|
||||||
|
|
||||||
- ‘Derivative Works’: the works or software that could be created by the
|
|
||||||
Licensee, based upon the Original Work or modifications thereof. This Licence
|
|
||||||
does not define the extent of modification or dependence on the Original Work
|
|
||||||
required in order to classify a work as a Derivative Work; this extent is
|
|
||||||
determined by copyright law applicable in the country mentioned in Article 15.
|
|
||||||
|
|
||||||
- ‘The Work’: the Original Work or its Derivative Works.
|
|
||||||
|
|
||||||
- ‘The Source Code’: the human-readable form of the Work which is the most
|
|
||||||
convenient for people to study and modify.
|
|
||||||
|
|
||||||
- ‘The Executable Code’: any code which has generally been compiled and which is
|
|
||||||
meant to be interpreted by a computer as a program.
|
|
||||||
|
|
||||||
- ‘The Licensor’: the natural or legal person that distributes or communicates
|
|
||||||
the Work under the Licence.
|
|
||||||
|
|
||||||
- ‘Contributor(s)’: any natural or legal person who modifies the Work under the
|
|
||||||
Licence, or otherwise contributes to the creation of a Derivative Work.
|
|
||||||
|
|
||||||
- ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
|
|
||||||
the Work under the terms of the Licence.
|
|
||||||
|
|
||||||
- ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
|
|
||||||
renting, distributing, communicating, transmitting, or otherwise making
|
|
||||||
available, online or offline, copies of the Work or providing access to its
|
|
||||||
essential functionalities at the disposal of any other natural or legal
|
|
||||||
person.
|
|
||||||
|
|
||||||
2. Scope of the rights granted by the Licence
|
|
||||||
|
|
||||||
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
|
||||||
sublicensable licence to do the following, for the duration of copyright vested
|
|
||||||
in the Original Work:
|
|
||||||
|
|
||||||
- use the Work in any circumstance and for all usage,
|
|
||||||
- reproduce the Work,
|
|
||||||
- modify the Work, and make Derivative Works based upon the Work,
|
|
||||||
- communicate to the public, including the right to make available or display
|
|
||||||
the Work or copies thereof to the public and perform publicly, as the case may
|
|
||||||
be, the Work,
|
|
||||||
- distribute the Work or copies thereof,
|
|
||||||
- lend and rent the Work or copies thereof,
|
|
||||||
- sublicense rights in the Work or copies thereof.
|
|
||||||
|
|
||||||
Those rights can be exercised on any media, supports and formats, whether now
|
|
||||||
known or later invented, as far as the applicable law permits so.
|
|
||||||
|
|
||||||
In the countries where moral rights apply, the Licensor waives his right to
|
|
||||||
exercise his moral right to the extent allowed by law in order to make effective
|
|
||||||
the licence of the economic rights here above listed.
|
|
||||||
|
|
||||||
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
|
|
||||||
any patents held by the Licensor, to the extent necessary to make use of the
|
|
||||||
rights granted on the Work under this Licence.
|
|
||||||
|
|
||||||
3. Communication of the Source Code
|
|
||||||
|
|
||||||
The Licensor may provide the Work either in its Source Code form, or as
|
|
||||||
Executable Code. If the Work is provided as Executable Code, the Licensor
|
|
||||||
provides in addition a machine-readable copy of the Source Code of the Work
|
|
||||||
along with each copy of the Work that the Licensor distributes or indicates, in
|
|
||||||
a notice following the copyright notice attached to the Work, a repository where
|
|
||||||
the Source Code is easily and freely accessible for as long as the Licensor
|
|
||||||
continues to distribute or communicate the Work.
|
|
||||||
|
|
||||||
4. Limitations on copyright
|
|
||||||
|
|
||||||
Nothing in this Licence is intended to deprive the Licensee of the benefits from
|
|
||||||
any exception or limitation to the exclusive rights of the rights owners in the
|
|
||||||
Work, of the exhaustion of those rights or of other applicable limitations
|
|
||||||
thereto.
|
|
||||||
|
|
||||||
5. Obligations of the Licensee
|
|
||||||
|
|
||||||
The grant of the rights mentioned above is subject to some restrictions and
|
|
||||||
obligations imposed on the Licensee. Those obligations are the following:
|
|
||||||
|
|
||||||
Attribution right: The Licensee shall keep intact all copyright, patent or
|
|
||||||
trademarks notices and all notices that refer to the Licence and to the
|
|
||||||
disclaimer of warranties. The Licensee must include a copy of such notices and a
|
|
||||||
copy of the Licence with every copy of the Work he/she distributes or
|
|
||||||
communicates. The Licensee must cause any Derivative Work to carry prominent
|
|
||||||
notices stating that the Work has been modified and the date of modification.
|
|
||||||
|
|
||||||
Copyleft clause: If the Licensee distributes or communicates copies of the
|
|
||||||
Original Works or Derivative Works, this Distribution or Communication will be
|
|
||||||
done under the terms of this Licence or of a later version of this Licence
|
|
||||||
unless the Original Work is expressly distributed only under this version of the
|
|
||||||
Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
|
|
||||||
(becoming Licensor) cannot offer or impose any additional terms or conditions on
|
|
||||||
the Work or Derivative Work that alter or restrict the terms of the Licence.
|
|
||||||
|
|
||||||
Compatibility clause: If the Licensee Distributes or Communicates Derivative
|
|
||||||
Works or copies thereof based upon both the Work and another work licensed under
|
|
||||||
a Compatible Licence, this Distribution or Communication can be done under the
|
|
||||||
terms of this Compatible Licence. For the sake of this clause, ‘Compatible
|
|
||||||
Licence’ refers to the licences listed in the appendix attached to this Licence.
|
|
||||||
Should the Licensee's obligations under the Compatible Licence conflict with
|
|
||||||
his/her obligations under this Licence, the obligations of the Compatible
|
|
||||||
Licence shall prevail.
|
|
||||||
|
|
||||||
Provision of Source Code: When distributing or communicating copies of the Work,
|
|
||||||
the Licensee will provide a machine-readable copy of the Source Code or indicate
|
|
||||||
a repository where this Source will be easily and freely available for as long
|
|
||||||
as the Licensee continues to distribute or communicate the Work.
|
|
||||||
|
|
||||||
Legal Protection: This Licence does not grant permission to use the trade names,
|
|
||||||
trademarks, service marks, or names of the Licensor, except as required for
|
|
||||||
reasonable and customary use in describing the origin of the Work and
|
|
||||||
reproducing the content of the copyright notice.
|
|
||||||
|
|
||||||
6. Chain of Authorship
|
|
||||||
|
|
||||||
The original Licensor warrants that the copyright in the Original Work granted
|
|
||||||
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
|
||||||
power and authority to grant the Licence.
|
|
||||||
|
|
||||||
Each Contributor warrants that the copyright in the modifications he/she brings
|
|
||||||
to the Work are owned by him/her or licensed to him/her and that he/she has the
|
|
||||||
power and authority to grant the Licence.
|
|
||||||
|
|
||||||
Each time You accept the Licence, the original Licensor and subsequent
|
|
||||||
Contributors grant You a licence to their contributions to the Work, under the
|
|
||||||
terms of this Licence.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty
|
|
||||||
|
|
||||||
The Work is a work in progress, which is continuously improved by numerous
|
|
||||||
Contributors. It is not a finished work and may therefore contain defects or
|
|
||||||
‘bugs’ inherent to this type of development.
|
|
||||||
|
|
||||||
For the above reason, the Work is provided under the Licence on an ‘as is’ basis
|
|
||||||
and without warranties of any kind concerning the Work, including without
|
|
||||||
limitation merchantability, fitness for a particular purpose, absence of defects
|
|
||||||
or errors, accuracy, non-infringement of intellectual property rights other than
|
|
||||||
copyright as stated in Article 6 of this Licence.
|
|
||||||
|
|
||||||
This disclaimer of warranty is an essential part of the Licence and a condition
|
|
||||||
for the grant of any rights to the Work.
|
|
||||||
|
|
||||||
8. Disclaimer of Liability
|
|
||||||
|
|
||||||
Except in the cases of wilful misconduct or damages directly caused to natural
|
|
||||||
persons, the Licensor will in no event be liable for any direct or indirect,
|
|
||||||
material or moral, damages of any kind, arising out of the Licence or of the use
|
|
||||||
of the Work, including without limitation, damages for loss of goodwill, work
|
|
||||||
stoppage, computer failure or malfunction, loss of data or any commercial
|
|
||||||
damage, even if the Licensor has been advised of the possibility of such damage.
|
|
||||||
However, the Licensor will be liable under statutory product liability laws as
|
|
||||||
far such laws apply to the Work.
|
|
||||||
|
|
||||||
9. Additional agreements
|
|
||||||
|
|
||||||
While distributing the Work, You may choose to conclude an additional agreement,
|
|
||||||
defining obligations or services consistent with this Licence. However, if
|
|
||||||
accepting obligations, You may act only on your own behalf and on your sole
|
|
||||||
responsibility, not on behalf of the original Licensor or any other Contributor,
|
|
||||||
and only if You agree to indemnify, defend, and hold each Contributor harmless
|
|
||||||
for any liability incurred by, or claims asserted against such Contributor by
|
|
||||||
the fact You have accepted any warranty or additional liability.
|
|
||||||
|
|
||||||
10. Acceptance of the Licence
|
|
||||||
|
|
||||||
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
|
|
||||||
placed under the bottom of a window displaying the text of this Licence or by
|
|
||||||
affirming consent in any other similar way, in accordance with the rules of
|
|
||||||
applicable law. Clicking on that icon indicates your clear and irrevocable
|
|
||||||
acceptance of this Licence and all of its terms and conditions.
|
|
||||||
|
|
||||||
Similarly, you irrevocably accept this Licence and all of its terms and
|
|
||||||
conditions by exercising any rights granted to You by Article 2 of this Licence,
|
|
||||||
such as the use of the Work, the creation by You of a Derivative Work or the
|
|
||||||
Distribution or Communication by You of the Work or copies thereof.
|
|
||||||
|
|
||||||
11. Information to the public
|
|
||||||
|
|
||||||
In case of any Distribution or Communication of the Work by means of electronic
|
|
||||||
communication by You (for example, by offering to download the Work from a
|
|
||||||
remote location) the distribution channel or media (for example, a website) must
|
|
||||||
at least provide to the public the information requested by the applicable law
|
|
||||||
regarding the Licensor, the Licence and the way it may be accessible, concluded,
|
|
||||||
stored and reproduced by the Licensee.
|
|
||||||
|
|
||||||
12. Termination of the Licence
|
|
||||||
|
|
||||||
The Licence and the rights granted hereunder will terminate automatically upon
|
|
||||||
any breach by the Licensee of the terms of the Licence.
|
|
||||||
|
|
||||||
Such a termination will not terminate the licences of any person who has
|
|
||||||
received the Work from the Licensee under the Licence, provided such persons
|
|
||||||
remain in full compliance with the Licence.
|
|
||||||
|
|
||||||
13. Miscellaneous
|
|
||||||
|
|
||||||
Without prejudice of Article 9 above, the Licence represents the complete
|
|
||||||
agreement between the Parties as to the Work.
|
|
||||||
|
|
||||||
If any provision of the Licence is invalid or unenforceable under applicable
|
|
||||||
law, this will not affect the validity or enforceability of the Licence as a
|
|
||||||
whole. Such provision will be construed or reformed so as necessary to make it
|
|
||||||
valid and enforceable.
|
|
||||||
|
|
||||||
The European Commission may publish other linguistic versions or new versions of
|
|
||||||
this Licence or updated versions of the Appendix, so far this is required and
|
|
||||||
reasonable, without reducing the scope of the rights granted by the Licence. New
|
|
||||||
versions of the Licence will be published with a unique version number.
|
|
||||||
|
|
||||||
All linguistic versions of this Licence, approved by the European Commission,
|
|
||||||
have identical value. Parties can take advantage of the linguistic version of
|
|
||||||
their choice.
|
|
||||||
|
|
||||||
14. Jurisdiction
|
|
||||||
|
|
||||||
Without prejudice to specific agreement between parties,
|
|
||||||
|
|
||||||
- any litigation resulting from the interpretation of this License, arising
|
|
||||||
between the European Union institutions, bodies, offices or agencies, as a
|
|
||||||
Licensor, and any Licensee, will be subject to the jurisdiction of the Court
|
|
||||||
of Justice of the European Union, as laid down in article 272 of the Treaty on
|
|
||||||
the Functioning of the European Union,
|
|
||||||
|
|
||||||
- any litigation arising between other parties and resulting from the
|
|
||||||
interpretation of this License, will be subject to the exclusive jurisdiction
|
|
||||||
of the competent court where the Licensor resides or conducts its primary
|
|
||||||
business.
|
|
||||||
|
|
||||||
15. Applicable Law
|
|
||||||
|
|
||||||
Without prejudice to specific agreement between parties,
|
|
||||||
|
|
||||||
- this Licence shall be governed by the law of the European Union Member State
|
|
||||||
where the Licensor has his seat, resides or has his registered office,
|
|
||||||
|
|
||||||
- this licence shall be governed by Belgian law if the Licensor has no seat,
|
|
||||||
residence or registered office inside a European Union Member State.
|
|
||||||
|
|
||||||
Appendix
|
|
||||||
|
|
||||||
‘Compatible Licences’ according to Article 5 EUPL are:
|
|
||||||
|
|
||||||
- GNU General Public License (GPL) v. 2, v. 3
|
|
||||||
- GNU Affero General Public License (AGPL) v. 3
|
|
||||||
- Open Software License (OSL) v. 2.1, v. 3.0
|
|
||||||
- Eclipse Public License (EPL) v. 1.0
|
|
||||||
- CeCILL v. 2.0, v. 2.1
|
|
||||||
- Mozilla Public Licence (MPL) v. 2
|
|
||||||
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
|
||||||
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
|
|
||||||
works other than software
|
|
||||||
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
|
||||||
- Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
|
|
||||||
Reciprocity (LiLiQ-R+).
|
|
||||||
|
|
||||||
The European Commission may update this Appendix to later versions of the above
|
|
||||||
licences without producing a new version of the EUPL, as long as they provide
|
|
||||||
the rights granted in Article 2 of this Licence and protect the covered Source
|
|
||||||
Code from exclusive appropriation.
|
|
||||||
|
|
||||||
All other changes or additions to this Appendix require the production of a new
|
|
||||||
EUPL version.
|
|
||||||
217
README.md
217
README.md
|
|
@ -1,217 +0,0 @@
|
||||||
# Enchantrix
|
|
||||||
|
|
||||||
[](https://goreportcard.com/report/github.com/Snider/Enchantrix)
|
|
||||||
[](https://godoc.org/github.com/Snider/Enchantrix)
|
|
||||||
[](https://github.com/Snider/Enchantrix/actions/workflows/go.yml)
|
|
||||||
[](https://codecov.io/github/Snider/Enchantrix)
|
|
||||||
[](https://github.com/Snider/Enchantrix/releases/latest)
|
|
||||||
[](https://github.com/Snider/Enchantrix/blob/main/LICENCE)
|
|
||||||
[](https://go.dev/)
|
|
||||||
|
|
||||||
A Go-based encryption and data transformation library designed for secure handling of sensitive data. Enchantrix provides composable transformation pipelines, a flexible binary container format, and defense-in-depth encryption with pre-obfuscation.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Sigil Transformation Framework** - Composable, reversible data transformations (encoding, compression, hashing)
|
|
||||||
- **Pre-Obfuscation Layer** - Side-channel attack mitigation for AEAD ciphers
|
|
||||||
- **.trix Container Format** - Protocol-agnostic binary format with JSON metadata
|
|
||||||
- **Multiple Hash Algorithms** - SHA-2, SHA-3, BLAKE2, RIPEMD-160, and the custom LTHN algorithm
|
|
||||||
- **Full PGP Support** - Key generation, encryption, decryption, signing, and verification
|
|
||||||
- **RSA Operations** - Key generation, encryption, and decryption
|
|
||||||
- **CLI Tool** - `trix` command for encoding, decoding, and transformations
|
|
||||||
|
|
||||||
## Quick Start
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
```shell
|
|
||||||
go get github.com/Snider/Enchantrix
|
|
||||||
```
|
|
||||||
|
|
||||||
### Install CLI Tool
|
|
||||||
|
|
||||||
```shell
|
|
||||||
go install github.com/Snider/Enchantrix/cmd/trix@latest
|
|
||||||
```
|
|
||||||
|
|
||||||
### Basic Usage
|
|
||||||
|
|
||||||
#### Sigil Transformations
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/enchantrix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Create sigils
|
|
||||||
hexSigil, _ := enchantrix.NewSigil("hex")
|
|
||||||
base64Sigil, _ := enchantrix.NewSigil("base64")
|
|
||||||
|
|
||||||
// Apply transformations
|
|
||||||
data := []byte("Hello, Enchantrix!")
|
|
||||||
encoded, _ := enchantrix.Transmute(data, []enchantrix.Sigil{hexSigil, base64Sigil})
|
|
||||||
|
|
||||||
fmt.Printf("Encoded: %s\n", encoded)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Hashing
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
service := crypt.NewService()
|
|
||||||
|
|
||||||
hash := service.Hash(crypt.SHA256, "Hello, World!")
|
|
||||||
fmt.Printf("SHA-256: %s\n", hash)
|
|
||||||
|
|
||||||
// LTHN quasi-salted hash
|
|
||||||
lthnHash := service.Hash(crypt.LTHN, "Hello, World!")
|
|
||||||
fmt.Printf("LTHN: %s\n", lthnHash)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Encrypted .trix Container
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/trix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
container := &trix.Trix{
|
|
||||||
Header: map[string]interface{}{
|
|
||||||
"content_type": "text/plain",
|
|
||||||
"created_at": "2025-01-13T12:00:00Z",
|
|
||||||
},
|
|
||||||
Payload: []byte("Secret message"),
|
|
||||||
InSigils: []string{"gzip", "base64"},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pack with sigils
|
|
||||||
container.Pack()
|
|
||||||
|
|
||||||
// Encode to binary
|
|
||||||
encoded, _ := trix.Encode(container, "MYAP", nil)
|
|
||||||
fmt.Printf("Container size: %d bytes\n", len(encoded))
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### CLI Examples
|
|
||||||
|
|
||||||
```shell
|
|
||||||
# Encode with sigils
|
|
||||||
echo "Hello, Trix!" | trix encode --output message.trix --magic TRIX base64
|
|
||||||
|
|
||||||
# Decode
|
|
||||||
trix decode --input message.trix --output message.txt --magic TRIX base64
|
|
||||||
|
|
||||||
# Hash data
|
|
||||||
echo "Hello, World!" | trix hash sha256
|
|
||||||
|
|
||||||
# Apply sigil directly
|
|
||||||
echo "Hello" | trix hex
|
|
||||||
# Output: 48656c6c6f
|
|
||||||
```
|
|
||||||
|
|
||||||
## Specifications
|
|
||||||
|
|
||||||
Enchantrix includes formal RFC-style specifications for its core protocols:
|
|
||||||
|
|
||||||
| RFC | Title | Description |
|
|
||||||
|-----|-------|-------------|
|
|
||||||
| [RFC-0001](rfcs/RFC-0001-Pre-Obfuscation-Layer.md) | Pre-Obfuscation Layer | Side-channel mitigation for AEAD ciphers |
|
|
||||||
| [RFC-0002](rfcs/RFC-0002-Trix-Container-Format.md) | TRIX Container Format | Binary container with JSON metadata |
|
|
||||||
| [RFC-0003](rfcs/RFC-0003-Sigil-Transformation-Framework.md) | Sigil Framework | Composable data transformation interface |
|
|
||||||
| [RFC-0004](rfcs/RFC-0004-LTHN-Hash-Algorithm.md) | LTHN Hash | Quasi-salted deterministic hashing |
|
|
||||||
|
|
||||||
## Available Sigils
|
|
||||||
|
|
||||||
| Category | Sigils |
|
|
||||||
|----------|--------|
|
|
||||||
| **Encoding** | `hex`, `base64` |
|
|
||||||
| **Compression** | `gzip` |
|
|
||||||
| **Formatting** | `json`, `json-indent` |
|
|
||||||
| **Transform** | `reverse` |
|
|
||||||
| **Hashing** | `md4`, `md5`, `sha1`, `sha224`, `sha256`, `sha384`, `sha512`, `sha3-224`, `sha3-256`, `sha3-384`, `sha3-512`, `sha512-224`, `sha512-256`, `ripemd160`, `blake2s-256`, `blake2b-256`, `blake2b-384`, `blake2b-512` |
|
|
||||||
|
|
||||||
## Project Structure
|
|
||||||
|
|
||||||
```
|
|
||||||
Enchantrix/
|
|
||||||
├── cmd/trix/ # CLI tool
|
|
||||||
├── pkg/
|
|
||||||
│ ├── enchantrix/ # Sigil framework and crypto sigils
|
|
||||||
│ ├── trix/ # .trix container format
|
|
||||||
│ └── crypt/ # Cryptographic services (hash, RSA, PGP)
|
|
||||||
├── rfcs/ # Protocol specifications
|
|
||||||
├── examples/ # Usage examples
|
|
||||||
└── docs/ # MkDocs documentation
|
|
||||||
```
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
Full documentation is available via MkDocs:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
# Install dependencies
|
|
||||||
pip install mkdocs mkdocs-material
|
|
||||||
|
|
||||||
# Serve locally
|
|
||||||
mkdocs serve -a 127.0.0.1:8000
|
|
||||||
|
|
||||||
# Build static site
|
|
||||||
mkdocs build --strict
|
|
||||||
```
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
### Requirements
|
|
||||||
|
|
||||||
- Go 1.25 or later
|
|
||||||
|
|
||||||
### Running Tests
|
|
||||||
|
|
||||||
```shell
|
|
||||||
# Run all tests
|
|
||||||
go test ./...
|
|
||||||
|
|
||||||
# Run with race detection
|
|
||||||
go test -race ./...
|
|
||||||
|
|
||||||
# Run with coverage
|
|
||||||
go test -coverprofile=coverage.out ./...
|
|
||||||
```
|
|
||||||
|
|
||||||
### Test-Driven Development
|
|
||||||
|
|
||||||
This project follows strict TDD methodology. All new functionality must include comprehensive tests.
|
|
||||||
|
|
||||||
## Releases
|
|
||||||
|
|
||||||
Built with GoReleaser:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
# Snapshot release (local, no publish)
|
|
||||||
goreleaser release --snapshot --clean
|
|
||||||
|
|
||||||
# Production release (requires Git tag)
|
|
||||||
goreleaser release --clean
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
See [LICENCE](LICENCE) for details.
|
|
||||||
43
Taskfile.yml
43
Taskfile.yml
|
|
@ -1,43 +0,0 @@
|
||||||
version: '3'
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
test:
|
|
||||||
desc: "Run all tests and generate a coverage report"
|
|
||||||
cmds:
|
|
||||||
- go vet ./...
|
|
||||||
- go test -v -coverprofile=coverage.out ./...
|
|
||||||
|
|
||||||
build:
|
|
||||||
desc: "Build the project"
|
|
||||||
cmds:
|
|
||||||
- go build -v ./...
|
|
||||||
|
|
||||||
fmt:
|
|
||||||
desc: "Format the code"
|
|
||||||
cmds:
|
|
||||||
- go fmt ./...
|
|
||||||
|
|
||||||
vet:
|
|
||||||
desc: "Run go vet"
|
|
||||||
cmds:
|
|
||||||
- go vet ./...
|
|
||||||
|
|
||||||
docs:serve:
|
|
||||||
desc: "Serve the MkDocs site locally"
|
|
||||||
cmds:
|
|
||||||
- mkdocs serve -a 127.0.0.1:8000
|
|
||||||
|
|
||||||
docs:build:
|
|
||||||
desc: "Build the MkDocs site"
|
|
||||||
cmds:
|
|
||||||
- mkdocs build --strict
|
|
||||||
|
|
||||||
release:snapshot:
|
|
||||||
desc: "Create a snapshot release with GoReleaser (no publishing)"
|
|
||||||
cmds:
|
|
||||||
- goreleaser release --snapshot --clean
|
|
||||||
|
|
||||||
release:
|
|
||||||
desc: "Create a release with GoReleaser"
|
|
||||||
cmds:
|
|
||||||
- goreleaser release --clean
|
|
||||||
BIN
assets/images/favicon.png
Normal file
BIN
assets/images/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
16
assets/javascripts/bundle.f55a23d4.min.js
vendored
Normal file
16
assets/javascripts/bundle.f55a23d4.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
assets/javascripts/bundle.f55a23d4.min.js.map
Normal file
7
assets/javascripts/bundle.f55a23d4.min.js.map
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.ar.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.ar.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.da.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.da.min.js
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*!
|
||||||
|
* Lunr languages, `Danish` language
|
||||||
|
* https://github.com/MihaiValentin/lunr-languages
|
||||||
|
*
|
||||||
|
* Copyright 2014, Mihai Valentin
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*/
|
||||||
|
/*!
|
||||||
|
* based on
|
||||||
|
* Snowball JavaScript Library v0.3
|
||||||
|
* http://code.google.com/p/urim/
|
||||||
|
* http://snowball.tartarus.org/
|
||||||
|
*
|
||||||
|
* Copyright 2010, Oleg Mazko
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*/
|
||||||
|
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.da=function(){this.pipeline.reset(),this.pipeline.add(e.da.trimmer,e.da.stopWordFilter,e.da.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.da.stemmer))},e.da.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.da.trimmer=e.trimmerSupport.generateTrimmer(e.da.wordCharacters),e.Pipeline.registerFunction(e.da.trimmer,"trimmer-da"),e.da.stemmer=function(){var r=e.stemmerSupport.Among,i=e.stemmerSupport.SnowballProgram,n=new function(){function e(){var e,r=f.cursor+3;if(d=f.limit,0<=r&&r<=f.limit){for(a=r;;){if(e=f.cursor,f.in_grouping(w,97,248)){f.cursor=e;break}if(f.cursor=e,e>=f.limit)return;f.cursor++}for(;!f.out_grouping(w,97,248);){if(f.cursor>=f.limit)return;f.cursor++}d=f.cursor,d<a&&(d=a)}}function n(){var e,r;if(f.cursor>=d&&(r=f.limit_backward,f.limit_backward=d,f.ket=f.cursor,e=f.find_among_b(c,32),f.limit_backward=r,e))switch(f.bra=f.cursor,e){case 1:f.slice_del();break;case 2:f.in_grouping_b(p,97,229)&&f.slice_del()}}function t(){var e,r=f.limit-f.cursor;f.cursor>=d&&(e=f.limit_backward,f.limit_backward=d,f.ket=f.cursor,f.find_among_b(l,4)?(f.bra=f.cursor,f.limit_backward=e,f.cursor=f.limit-r,f.cursor>f.limit_backward&&(f.cursor--,f.bra=f.cursor,f.slice_del())):f.limit_backward=e)}function s(){var e,r,i,n=f.limit-f.cursor;if(f.ket=f.cursor,f.eq_s_b(2,"st")&&(f.bra=f.cursor,f.eq_s_b(2,"ig")&&f.slice_del()),f.cursor=f.limit-n,f.cursor>=d&&(r=f.limit_backward,f.limit_backward=d,f.ket=f.cursor,e=f.find_among_b(m,5),f.limit_backward=r,e))switch(f.bra=f.cursor,e){case 1:f.slice_del(),i=f.limit-f.cursor,t(),f.cursor=f.limit-i;break;case 2:f.slice_from("løs")}}function o(){var e;f.cursor>=d&&(e=f.limit_backward,f.limit_backward=d,f.ket=f.cursor,f.out_grouping_b(w,97,248)?(f.bra=f.cursor,u=f.slice_to(u),f.limit_backward=e,f.eq_v_b(u)&&f.slice_del()):f.limit_backward=e)}var a,d,u,c=[new r("hed",-1,1),new r("ethed",0,1),new r("ered",-1,1),new r("e",-1,1),new r("erede",3,1),new r("ende",3,1),new r("erende",5,1),new r("ene",3,1),new r("erne",3,1),new r("ere",3,1),new r("en",-1,1),new r("heden",10,1),new r("eren",10,1),new r("er",-1,1),new r("heder",13,1),new r("erer",13,1),new r("s",-1,2),new r("heds",16,1),new r("es",16,1),new r("endes",18,1),new r("erendes",19,1),new r("enes",18,1),new r("ernes",18,1),new r("eres",18,1),new r("ens",16,1),new r("hedens",24,1),new r("erens",24,1),new r("ers",16,1),new r("ets",16,1),new r("erets",28,1),new r("et",-1,1),new r("eret",30,1)],l=[new r("gd",-1,-1),new r("dt",-1,-1),new r("gt",-1,-1),new r("kt",-1,-1)],m=[new r("ig",-1,1),new r("lig",0,1),new r("elig",1,1),new r("els",-1,1),new r("løst",-1,2)],w=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,48,0,128],p=[239,254,42,3,0,0,0,0,0,0,0,0,0,0,0,0,16],f=new i;this.setCurrent=function(e){f.setCurrent(e)},this.getCurrent=function(){return f.getCurrent()},this.stem=function(){var r=f.cursor;return e(),f.limit_backward=r,f.cursor=f.limit,n(),f.cursor=f.limit,t(),f.cursor=f.limit,s(),f.cursor=f.limit,o(),!0}};return function(e){return"function"==typeof e.update?e.update(function(e){return n.setCurrent(e),n.stem(),n.getCurrent()}):(n.setCurrent(e),n.stem(),n.getCurrent())}}(),e.Pipeline.registerFunction(e.da.stemmer,"stemmer-da"),e.da.stopWordFilter=e.generateStopWordFilter("ad af alle alt anden at blev blive bliver da de dem den denne der deres det dette dig din disse dog du efter eller en end er et for fra ham han hans har havde have hende hendes her hos hun hvad hvis hvor i ikke ind jeg jer jo kunne man mange med meget men mig min mine mit mod ned noget nogle nu når og også om op os over på selv sig sin sine sit skal skulle som sådan thi til ud under var vi vil ville vor være været".split(" ")),e.Pipeline.registerFunction(e.da.stopWordFilter,"stopWordFilter-da")}});
|
||||||
18
assets/javascripts/lunr/min/lunr.de.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.de.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.du.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.du.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.el.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.el.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.es.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.es.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.fi.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.fi.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.fr.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.fr.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.he.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.he.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.hi.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.hi.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.hi=function(){this.pipeline.reset(),this.pipeline.add(e.hi.trimmer,e.hi.stopWordFilter,e.hi.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.hi.stemmer))},e.hi.wordCharacters="ऀ-ःऄ-एऐ-टठ-यर-िी-ॏॐ-य़ॠ-९॰-ॿa-zA-Za-zA-Z0-90-9",e.hi.trimmer=e.trimmerSupport.generateTrimmer(e.hi.wordCharacters),e.Pipeline.registerFunction(e.hi.trimmer,"trimmer-hi"),e.hi.stopWordFilter=e.generateStopWordFilter("अत अपना अपनी अपने अभी अंदर आदि आप इत्यादि इन इनका इन्हीं इन्हें इन्हों इस इसका इसकी इसके इसमें इसी इसे उन उनका उनकी उनके उनको उन्हीं उन्हें उन्हों उस उसके उसी उसे एक एवं एस ऐसे और कई कर करता करते करना करने करें कहते कहा का काफ़ी कि कितना किन्हें किन्हों किया किर किस किसी किसे की कुछ कुल के को कोई कौन कौनसा गया घर जब जहाँ जा जितना जिन जिन्हें जिन्हों जिस जिसे जीधर जैसा जैसे जो तक तब तरह तिन तिन्हें तिन्हों तिस तिसे तो था थी थे दबारा दिया दुसरा दूसरे दो द्वारा न नके नहीं ना निहायत नीचे ने पर पहले पूरा पे फिर बनी बही बहुत बाद बाला बिलकुल भी भीतर मगर मानो मे में यदि यह यहाँ यही या यिह ये रखें रहा रहे ऱ्वासा लिए लिये लेकिन व वग़ैरह वर्ग वह वहाँ वहीं वाले वुह वे वो सकता सकते सबसे सभी साथ साबुत साभ सारा से सो संग ही हुआ हुई हुए है हैं हो होता होती होते होना होने".split(" ")),e.hi.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var r=e.wordcut;r.init(),e.hi.tokenizer=function(i){if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(r){return isLunr2?new e.Token(r.toLowerCase()):r.toLowerCase()});var t=i.toString().toLowerCase().replace(/^\s+/,"");return r.cut(t).split("|")},e.Pipeline.registerFunction(e.hi.stemmer,"stemmer-hi"),e.Pipeline.registerFunction(e.hi.stopWordFilter,"stopWordFilter-hi")}});
|
||||||
18
assets/javascripts/lunr/min/lunr.hu.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.hu.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.hy.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.hy.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.hy=function(){this.pipeline.reset(),this.pipeline.add(e.hy.trimmer,e.hy.stopWordFilter)},e.hy.wordCharacters="[A-Za-z-֏ff-ﭏ]",e.hy.trimmer=e.trimmerSupport.generateTrimmer(e.hy.wordCharacters),e.Pipeline.registerFunction(e.hy.trimmer,"trimmer-hy"),e.hy.stopWordFilter=e.generateStopWordFilter("դու և եք էիր էիք հետո նաև նրանք որը վրա է որ պիտի են այս մեջ ն իր ու ի այդ որոնք այն կամ էր մի ես համար այլ իսկ էին ենք հետ ին թ էինք մենք նրա նա դուք եմ էի ըստ որպես ում".split(" ")),e.Pipeline.registerFunction(e.hy.stopWordFilter,"stopWordFilter-hy"),e.hy.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}(),e.Pipeline.registerFunction(e.hy.stemmer,"stemmer-hy")}});
|
||||||
18
assets/javascripts/lunr/min/lunr.it.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.it.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.ja.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.ja.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r="2"==e.version[0];e.ja=function(){this.pipeline.reset(),this.pipeline.add(e.ja.trimmer,e.ja.stopWordFilter,e.ja.stemmer),r?this.tokenizer=e.ja.tokenizer:(e.tokenizer&&(e.tokenizer=e.ja.tokenizer),this.tokenizerFn&&(this.tokenizerFn=e.ja.tokenizer))};var t=new e.TinySegmenter;e.ja.tokenizer=function(i){var n,o,s,p,a,u,m,l,c,f;if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(t){return r?new e.Token(t.toLowerCase()):t.toLowerCase()});for(o=i.toString().toLowerCase().replace(/^\s+/,""),n=o.length-1;n>=0;n--)if(/\S/.test(o.charAt(n))){o=o.substring(0,n+1);break}for(a=[],s=o.length,c=0,l=0;c<=s;c++)if(u=o.charAt(c),m=c-l,u.match(/\s/)||c==s){if(m>0)for(p=t.segment(o.slice(l,c)).filter(function(e){return!!e}),f=l,n=0;n<p.length;n++)r?a.push(new e.Token(p[n],{position:[f,p[n].length],index:a.length})):a.push(p[n]),f+=p[n].length;l=c+1}return a},e.ja.stemmer=function(){return function(e){return e}}(),e.Pipeline.registerFunction(e.ja.stemmer,"stemmer-ja"),e.ja.wordCharacters="一二三四五六七八九十百千万億兆一-龠々〆ヵヶぁ-んァ-ヴーア-ン゙a-zA-Za-zA-Z0-90-9",e.ja.trimmer=e.trimmerSupport.generateTrimmer(e.ja.wordCharacters),e.Pipeline.registerFunction(e.ja.trimmer,"trimmer-ja"),e.ja.stopWordFilter=e.generateStopWordFilter("これ それ あれ この その あの ここ そこ あそこ こちら どこ だれ なに なん 何 私 貴方 貴方方 我々 私達 あの人 あのかた 彼女 彼 です あります おります います は が の に を で え から まで より も どの と し それで しかし".split(" ")),e.Pipeline.registerFunction(e.ja.stopWordFilter,"stopWordFilter-ja"),e.jp=e.ja,e.Pipeline.registerFunction(e.jp.stemmer,"stemmer-jp"),e.Pipeline.registerFunction(e.jp.trimmer,"trimmer-jp"),e.Pipeline.registerFunction(e.jp.stopWordFilter,"stopWordFilter-jp")}});
|
||||||
1
assets/javascripts/lunr/min/lunr.jp.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.jp.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
module.exports=require("./lunr.ja");
|
||||||
1
assets/javascripts/lunr/min/lunr.kn.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.kn.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.kn=function(){this.pipeline.reset(),this.pipeline.add(e.kn.trimmer,e.kn.stopWordFilter,e.kn.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.kn.stemmer))},e.kn.wordCharacters="ಀ-಄ಅ-ಔಕ-ಹಾ-ೌ಼-ಽೕ-ೖೝ-ೞೠ-ೡೢ-ೣ೦-೯ೱ-ೳ",e.kn.trimmer=e.trimmerSupport.generateTrimmer(e.kn.wordCharacters),e.Pipeline.registerFunction(e.kn.trimmer,"trimmer-kn"),e.kn.stopWordFilter=e.generateStopWordFilter("ಮತ್ತು ಈ ಒಂದು ರಲ್ಲಿ ಹಾಗೂ ಎಂದು ಅಥವಾ ಇದು ರ ಅವರು ಎಂಬ ಮೇಲೆ ಅವರ ತನ್ನ ಆದರೆ ತಮ್ಮ ನಂತರ ಮೂಲಕ ಹೆಚ್ಚು ನ ಆ ಕೆಲವು ಅನೇಕ ಎರಡು ಹಾಗು ಪ್ರಮುಖ ಇದನ್ನು ಇದರ ಸುಮಾರು ಅದರ ಅದು ಮೊದಲ ಬಗ್ಗೆ ನಲ್ಲಿ ರಂದು ಇತರ ಅತ್ಯಂತ ಹೆಚ್ಚಿನ ಸಹ ಸಾಮಾನ್ಯವಾಗಿ ನೇ ಹಲವಾರು ಹೊಸ ದಿ ಕಡಿಮೆ ಯಾವುದೇ ಹೊಂದಿದೆ ದೊಡ್ಡ ಅನ್ನು ಇವರು ಪ್ರಕಾರ ಇದೆ ಮಾತ್ರ ಕೂಡ ಇಲ್ಲಿ ಎಲ್ಲಾ ವಿವಿಧ ಅದನ್ನು ಹಲವು ರಿಂದ ಕೇವಲ ದ ದಕ್ಷಿಣ ಗೆ ಅವನ ಅತಿ ನೆಯ ಬಹಳ ಕೆಲಸ ಎಲ್ಲ ಪ್ರತಿ ಇತ್ಯಾದಿ ಇವು ಬೇರೆ ಹೀಗೆ ನಡುವೆ ಇದಕ್ಕೆ ಎಸ್ ಇವರ ಮೊದಲು ಶ್ರೀ ಮಾಡುವ ಇದರಲ್ಲಿ ರೀತಿಯ ಮಾಡಿದ ಕಾಲ ಅಲ್ಲಿ ಮಾಡಲು ಅದೇ ಈಗ ಅವು ಗಳು ಎ ಎಂಬುದು ಅವನು ಅಂದರೆ ಅವರಿಗೆ ಇರುವ ವಿಶೇಷ ಮುಂದೆ ಅವುಗಳ ಮುಂತಾದ ಮೂಲ ಬಿ ಮೀ ಒಂದೇ ಇನ್ನೂ ಹೆಚ್ಚಾಗಿ ಮಾಡಿ ಅವರನ್ನು ಇದೇ ಯ ರೀತಿಯಲ್ಲಿ ಜೊತೆ ಅದರಲ್ಲಿ ಮಾಡಿದರು ನಡೆದ ಆಗ ಮತ್ತೆ ಪೂರ್ವ ಆತ ಬಂದ ಯಾವ ಒಟ್ಟು ಇತರೆ ಹಿಂದೆ ಪ್ರಮಾಣದ ಗಳನ್ನು ಕುರಿತು ಯು ಆದ್ದರಿಂದ ಅಲ್ಲದೆ ನಗರದ ಮೇಲಿನ ಏಕೆಂದರೆ ರಷ್ಟು ಎಂಬುದನ್ನು ಬಾರಿ ಎಂದರೆ ಹಿಂದಿನ ಆದರೂ ಆದ ಸಂಬಂಧಿಸಿದ ಮತ್ತೊಂದು ಸಿ ಆತನ ".split(" ")),e.kn.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var r=e.wordcut;r.init(),e.kn.tokenizer=function(t){if(!arguments.length||null==t||void 0==t)return[];if(Array.isArray(t))return t.map(function(r){return isLunr2?new e.Token(r.toLowerCase()):r.toLowerCase()});var n=t.toString().toLowerCase().replace(/^\s+/,"");return r.cut(n).split("|")},e.Pipeline.registerFunction(e.kn.stemmer,"stemmer-kn"),e.Pipeline.registerFunction(e.kn.stopWordFilter,"stopWordFilter-kn")}});
|
||||||
1
assets/javascripts/lunr/min/lunr.ko.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.ko.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.multi.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.multi.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(e.lunr)}(this,function(){return function(e){e.multiLanguage=function(){for(var t=Array.prototype.slice.call(arguments),i=t.join("-"),r="",n=[],s=[],p=0;p<t.length;++p)"en"==t[p]?(r+="\\w",n.unshift(e.stopWordFilter),n.push(e.stemmer),s.push(e.stemmer)):(r+=e[t[p]].wordCharacters,e[t[p]].stopWordFilter&&n.unshift(e[t[p]].stopWordFilter),e[t[p]].stemmer&&(n.push(e[t[p]].stemmer),s.push(e[t[p]].stemmer)));var o=e.trimmerSupport.generateTrimmer(r);return e.Pipeline.registerFunction(o,"lunr-multi-trimmer-"+i),n.unshift(o),function(){this.pipeline.reset(),this.pipeline.add.apply(this.pipeline,n),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add.apply(this.searchPipeline,s))}}}});
|
||||||
18
assets/javascripts/lunr/min/lunr.nl.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.nl.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.no.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.no.min.js
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*!
|
||||||
|
* Lunr languages, `Norwegian` language
|
||||||
|
* https://github.com/MihaiValentin/lunr-languages
|
||||||
|
*
|
||||||
|
* Copyright 2014, Mihai Valentin
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*/
|
||||||
|
/*!
|
||||||
|
* based on
|
||||||
|
* Snowball JavaScript Library v0.3
|
||||||
|
* http://code.google.com/p/urim/
|
||||||
|
* http://snowball.tartarus.org/
|
||||||
|
*
|
||||||
|
* Copyright 2010, Oleg Mazko
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*/
|
||||||
|
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.no=function(){this.pipeline.reset(),this.pipeline.add(e.no.trimmer,e.no.stopWordFilter,e.no.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.no.stemmer))},e.no.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.no.trimmer=e.trimmerSupport.generateTrimmer(e.no.wordCharacters),e.Pipeline.registerFunction(e.no.trimmer,"trimmer-no"),e.no.stemmer=function(){var r=e.stemmerSupport.Among,n=e.stemmerSupport.SnowballProgram,i=new function(){function e(){var e,r=w.cursor+3;if(a=w.limit,0<=r||r<=w.limit){for(s=r;;){if(e=w.cursor,w.in_grouping(d,97,248)){w.cursor=e;break}if(e>=w.limit)return;w.cursor=e+1}for(;!w.out_grouping(d,97,248);){if(w.cursor>=w.limit)return;w.cursor++}a=w.cursor,a<s&&(a=s)}}function i(){var e,r,n;if(w.cursor>=a&&(r=w.limit_backward,w.limit_backward=a,w.ket=w.cursor,e=w.find_among_b(m,29),w.limit_backward=r,e))switch(w.bra=w.cursor,e){case 1:w.slice_del();break;case 2:n=w.limit-w.cursor,w.in_grouping_b(c,98,122)?w.slice_del():(w.cursor=w.limit-n,w.eq_s_b(1,"k")&&w.out_grouping_b(d,97,248)&&w.slice_del());break;case 3:w.slice_from("er")}}function t(){var e,r=w.limit-w.cursor;w.cursor>=a&&(e=w.limit_backward,w.limit_backward=a,w.ket=w.cursor,w.find_among_b(u,2)?(w.bra=w.cursor,w.limit_backward=e,w.cursor=w.limit-r,w.cursor>w.limit_backward&&(w.cursor--,w.bra=w.cursor,w.slice_del())):w.limit_backward=e)}function o(){var e,r;w.cursor>=a&&(r=w.limit_backward,w.limit_backward=a,w.ket=w.cursor,e=w.find_among_b(l,11),e?(w.bra=w.cursor,w.limit_backward=r,1==e&&w.slice_del()):w.limit_backward=r)}var s,a,m=[new r("a",-1,1),new r("e",-1,1),new r("ede",1,1),new r("ande",1,1),new r("ende",1,1),new r("ane",1,1),new r("ene",1,1),new r("hetene",6,1),new r("erte",1,3),new r("en",-1,1),new r("heten",9,1),new r("ar",-1,1),new r("er",-1,1),new r("heter",12,1),new r("s",-1,2),new r("as",14,1),new r("es",14,1),new r("edes",16,1),new r("endes",16,1),new r("enes",16,1),new r("hetenes",19,1),new r("ens",14,1),new r("hetens",21,1),new r("ers",14,1),new r("ets",14,1),new r("et",-1,1),new r("het",25,1),new r("ert",-1,3),new r("ast",-1,1)],u=[new r("dt",-1,-1),new r("vt",-1,-1)],l=[new r("leg",-1,1),new r("eleg",0,1),new r("ig",-1,1),new r("eig",2,1),new r("lig",2,1),new r("elig",4,1),new r("els",-1,1),new r("lov",-1,1),new r("elov",7,1),new r("slov",7,1),new r("hetslov",9,1)],d=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,48,0,128],c=[119,125,149,1],w=new n;this.setCurrent=function(e){w.setCurrent(e)},this.getCurrent=function(){return w.getCurrent()},this.stem=function(){var r=w.cursor;return e(),w.limit_backward=r,w.cursor=w.limit,i(),w.cursor=w.limit,t(),w.cursor=w.limit,o(),!0}};return function(e){return"function"==typeof e.update?e.update(function(e){return i.setCurrent(e),i.stem(),i.getCurrent()}):(i.setCurrent(e),i.stem(),i.getCurrent())}}(),e.Pipeline.registerFunction(e.no.stemmer,"stemmer-no"),e.no.stopWordFilter=e.generateStopWordFilter("alle at av bare begge ble blei bli blir blitt både båe da de deg dei deim deira deires dem den denne der dere deres det dette di din disse ditt du dykk dykkar då eg ein eit eitt eller elles en enn er et ett etter for fordi fra før ha hadde han hans har hennar henne hennes her hjå ho hoe honom hoss hossen hun hva hvem hver hvilke hvilken hvis hvor hvordan hvorfor i ikke ikkje ikkje ingen ingi inkje inn inni ja jeg kan kom korleis korso kun kunne kva kvar kvarhelst kven kvi kvifor man mange me med medan meg meget mellom men mi min mine mitt mot mykje ned no noe noen noka noko nokon nokor nokre nå når og også om opp oss over på samme seg selv si si sia sidan siden sin sine sitt sjøl skal skulle slik so som som somme somt så sånn til um upp ut uten var vart varte ved vere verte vi vil ville vore vors vort vår være være vært å".split(" ")),e.Pipeline.registerFunction(e.no.stopWordFilter,"stopWordFilter-no")}});
|
||||||
18
assets/javascripts/lunr/min/lunr.pt.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.pt.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.ro.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.ro.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
18
assets/javascripts/lunr/min/lunr.ru.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.ru.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.sa.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.sa.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.sa=function(){this.pipeline.reset(),this.pipeline.add(e.sa.trimmer,e.sa.stopWordFilter,e.sa.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.sa.stemmer))},e.sa.wordCharacters="ऀ-ःऄ-एऐ-टठ-यर-िी-ॏॐ-य़ॠ-९॰-ॿ꣠-꣱ꣲ-ꣷ꣸-ꣻ꣼-ꣽꣾ-ꣿᆰ0-ᆰ9",e.sa.trimmer=e.trimmerSupport.generateTrimmer(e.sa.wordCharacters),e.Pipeline.registerFunction(e.sa.trimmer,"trimmer-sa"),e.sa.stopWordFilter=e.generateStopWordFilter('तथा अयम् एकम् इत्यस्मिन् तथा तत् वा अयम् इत्यस्य ते आहूत उपरि तेषाम् किन्तु तेषाम् तदा इत्यनेन अधिकः इत्यस्य तत् केचन बहवः द्वि तथा महत्वपूर्णः अयम् अस्य विषये अयं अस्ति तत् प्रथमः विषये इत्युपरि इत्युपरि इतर अधिकतमः अधिकः अपि सामान्यतया ठ इतरेतर नूतनम् द न्यूनम् कश्चित् वा विशालः द सः अस्ति तदनुसारम् तत्र अस्ति केवलम् अपि अत्र सर्वे विविधाः तत् बहवः यतः इदानीम् द दक्षिण इत्यस्मै तस्य उपरि नथ अतीव कार्यम् सर्वे एकैकम् इत्यादि। एते सन्ति उत इत्थम् मध्ये एतदर्थं . स कस्य प्रथमः श्री. करोति अस्मिन् प्रकारः निर्मिता कालः तत्र कर्तुं समान अधुना ते सन्ति स एकः अस्ति सः अर्थात् तेषां कृते . स्थितम् विशेषः अग्रिम तेषाम् समान स्रोतः ख म समान इदानीमपि अधिकतया करोतु ते समान इत्यस्य वीथी सह यस्मिन् कृतवान् धृतः तदा पुनः पूर्वं सः आगतः किम् कुल इतर पुरा मात्रा स विषये उ अतएव अपि नगरस्य उपरि यतः प्रतिशतं कतरः कालः साधनानि भूत तथापि जात सम्बन्धि अन्यत् ग अतः अस्माकं स्वकीयाः अस्माकं इदानीं अन्तः इत्यादयः भवन्तः इत्यादयः एते एताः तस्य अस्य इदम् एते तेषां तेषां तेषां तान् तेषां तेषां तेषां समानः सः एकः च तादृशाः बहवः अन्ये च वदन्ति यत् कियत् कस्मै कस्मै यस्मै यस्मै यस्मै यस्मै न अतिनीचः किन्तु प्रथमं सम्पूर्णतया ततः चिरकालानन्तरं पुस्तकं सम्पूर्णतया अन्तः किन्तु अत्र वा इह इव श्रद्धाय अवशिष्यते परन्तु अन्ये वर्गाः सन्ति ते सन्ति शक्नुवन्ति सर्वे मिलित्वा सर्वे एकत्र"'.split(" ")),e.sa.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var r=e.wordcut;r.init(),e.sa.tokenizer=function(t){if(!arguments.length||null==t||void 0==t)return[];if(Array.isArray(t))return t.map(function(r){return isLunr2?new e.Token(r.toLowerCase()):r.toLowerCase()});var i=t.toString().toLowerCase().replace(/^\s+/,"");return r.cut(i).split("|")},e.Pipeline.registerFunction(e.sa.stemmer,"stemmer-sa"),e.Pipeline.registerFunction(e.sa.stopWordFilter,"stopWordFilter-sa")}});
|
||||||
1
assets/javascripts/lunr/min/lunr.stemmer.support.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.stemmer.support.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(r,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(r.lunr)}(this,function(){return function(r){r.stemmerSupport={Among:function(r,t,i,s){if(this.toCharArray=function(r){for(var t=r.length,i=new Array(t),s=0;s<t;s++)i[s]=r.charCodeAt(s);return i},!r&&""!=r||!t&&0!=t||!i)throw"Bad Among initialisation: s:"+r+", substring_i: "+t+", result: "+i;this.s_size=r.length,this.s=this.toCharArray(r),this.substring_i=t,this.result=i,this.method=s},SnowballProgram:function(){var r;return{bra:0,ket:0,limit:0,cursor:0,limit_backward:0,setCurrent:function(t){r=t,this.cursor=0,this.limit=t.length,this.limit_backward=0,this.bra=this.cursor,this.ket=this.limit},getCurrent:function(){var t=r;return r=null,t},in_grouping:function(t,i,s){if(this.cursor<this.limit){var e=r.charCodeAt(this.cursor);if(e<=s&&e>=i&&(e-=i,t[e>>3]&1<<(7&e)))return this.cursor++,!0}return!1},in_grouping_b:function(t,i,s){if(this.cursor>this.limit_backward){var e=r.charCodeAt(this.cursor-1);if(e<=s&&e>=i&&(e-=i,t[e>>3]&1<<(7&e)))return this.cursor--,!0}return!1},out_grouping:function(t,i,s){if(this.cursor<this.limit){var e=r.charCodeAt(this.cursor);if(e>s||e<i)return this.cursor++,!0;if(e-=i,!(t[e>>3]&1<<(7&e)))return this.cursor++,!0}return!1},out_grouping_b:function(t,i,s){if(this.cursor>this.limit_backward){var e=r.charCodeAt(this.cursor-1);if(e>s||e<i)return this.cursor--,!0;if(e-=i,!(t[e>>3]&1<<(7&e)))return this.cursor--,!0}return!1},eq_s:function(t,i){if(this.limit-this.cursor<t)return!1;for(var s=0;s<t;s++)if(r.charCodeAt(this.cursor+s)!=i.charCodeAt(s))return!1;return this.cursor+=t,!0},eq_s_b:function(t,i){if(this.cursor-this.limit_backward<t)return!1;for(var s=0;s<t;s++)if(r.charCodeAt(this.cursor-t+s)!=i.charCodeAt(s))return!1;return this.cursor-=t,!0},find_among:function(t,i){for(var s=0,e=i,n=this.cursor,u=this.limit,o=0,h=0,c=!1;;){for(var a=s+(e-s>>1),f=0,l=o<h?o:h,_=t[a],m=l;m<_.s_size;m++){if(n+l==u){f=-1;break}if(f=r.charCodeAt(n+l)-_.s[m])break;l++}if(f<0?(e=a,h=l):(s=a,o=l),e-s<=1){if(s>0||e==s||c)break;c=!0}}for(;;){var _=t[s];if(o>=_.s_size){if(this.cursor=n+_.s_size,!_.method)return _.result;var b=_.method();if(this.cursor=n+_.s_size,b)return _.result}if((s=_.substring_i)<0)return 0}},find_among_b:function(t,i){for(var s=0,e=i,n=this.cursor,u=this.limit_backward,o=0,h=0,c=!1;;){for(var a=s+(e-s>>1),f=0,l=o<h?o:h,_=t[a],m=_.s_size-1-l;m>=0;m--){if(n-l==u){f=-1;break}if(f=r.charCodeAt(n-1-l)-_.s[m])break;l++}if(f<0?(e=a,h=l):(s=a,o=l),e-s<=1){if(s>0||e==s||c)break;c=!0}}for(;;){var _=t[s];if(o>=_.s_size){if(this.cursor=n-_.s_size,!_.method)return _.result;var b=_.method();if(this.cursor=n-_.s_size,b)return _.result}if((s=_.substring_i)<0)return 0}},replace_s:function(t,i,s){var e=s.length-(i-t),n=r.substring(0,t),u=r.substring(i);return r=n+s+u,this.limit+=e,this.cursor>=i?this.cursor+=e:this.cursor>t&&(this.cursor=t),e},slice_check:function(){if(this.bra<0||this.bra>this.ket||this.ket>this.limit||this.limit>r.length)throw"faulty slice operation"},slice_from:function(r){this.slice_check(),this.replace_s(this.bra,this.ket,r)},slice_del:function(){this.slice_from("")},insert:function(r,t,i){var s=this.replace_s(r,t,i);r<=this.bra&&(this.bra+=s),r<=this.ket&&(this.ket+=s)},slice_to:function(){return this.slice_check(),r.substring(this.bra,this.ket)},eq_v_b:function(r){return this.eq_s_b(r.length,r)}}}},r.trimmerSupport={generateTrimmer:function(r){var t=new RegExp("^[^"+r+"]+"),i=new RegExp("[^"+r+"]+$");return function(r){return"function"==typeof r.update?r.update(function(r){return r.replace(t,"").replace(i,"")}):r.replace(t,"").replace(i,"")}}}}});
|
||||||
18
assets/javascripts/lunr/min/lunr.sv.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.sv.min.js
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*!
|
||||||
|
* Lunr languages, `Swedish` language
|
||||||
|
* https://github.com/MihaiValentin/lunr-languages
|
||||||
|
*
|
||||||
|
* Copyright 2014, Mihai Valentin
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*/
|
||||||
|
/*!
|
||||||
|
* based on
|
||||||
|
* Snowball JavaScript Library v0.3
|
||||||
|
* http://code.google.com/p/urim/
|
||||||
|
* http://snowball.tartarus.org/
|
||||||
|
*
|
||||||
|
* Copyright 2010, Oleg Mazko
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*/
|
||||||
|
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.sv=function(){this.pipeline.reset(),this.pipeline.add(e.sv.trimmer,e.sv.stopWordFilter,e.sv.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.sv.stemmer))},e.sv.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.sv.trimmer=e.trimmerSupport.generateTrimmer(e.sv.wordCharacters),e.Pipeline.registerFunction(e.sv.trimmer,"trimmer-sv"),e.sv.stemmer=function(){var r=e.stemmerSupport.Among,n=e.stemmerSupport.SnowballProgram,t=new function(){function e(){var e,r=w.cursor+3;if(o=w.limit,0<=r||r<=w.limit){for(a=r;;){if(e=w.cursor,w.in_grouping(l,97,246)){w.cursor=e;break}if(w.cursor=e,w.cursor>=w.limit)return;w.cursor++}for(;!w.out_grouping(l,97,246);){if(w.cursor>=w.limit)return;w.cursor++}o=w.cursor,o<a&&(o=a)}}function t(){var e,r=w.limit_backward;if(w.cursor>=o&&(w.limit_backward=o,w.cursor=w.limit,w.ket=w.cursor,e=w.find_among_b(u,37),w.limit_backward=r,e))switch(w.bra=w.cursor,e){case 1:w.slice_del();break;case 2:w.in_grouping_b(d,98,121)&&w.slice_del()}}function i(){var e=w.limit_backward;w.cursor>=o&&(w.limit_backward=o,w.cursor=w.limit,w.find_among_b(c,7)&&(w.cursor=w.limit,w.ket=w.cursor,w.cursor>w.limit_backward&&(w.bra=--w.cursor,w.slice_del())),w.limit_backward=e)}function s(){var e,r;if(w.cursor>=o){if(r=w.limit_backward,w.limit_backward=o,w.cursor=w.limit,w.ket=w.cursor,e=w.find_among_b(m,5))switch(w.bra=w.cursor,e){case 1:w.slice_del();break;case 2:w.slice_from("lös");break;case 3:w.slice_from("full")}w.limit_backward=r}}var a,o,u=[new r("a",-1,1),new r("arna",0,1),new r("erna",0,1),new r("heterna",2,1),new r("orna",0,1),new r("ad",-1,1),new r("e",-1,1),new r("ade",6,1),new r("ande",6,1),new r("arne",6,1),new r("are",6,1),new r("aste",6,1),new r("en",-1,1),new r("anden",12,1),new r("aren",12,1),new r("heten",12,1),new r("ern",-1,1),new r("ar",-1,1),new r("er",-1,1),new r("heter",18,1),new r("or",-1,1),new r("s",-1,2),new r("as",21,1),new r("arnas",22,1),new r("ernas",22,1),new r("ornas",22,1),new r("es",21,1),new r("ades",26,1),new r("andes",26,1),new r("ens",21,1),new r("arens",29,1),new r("hetens",29,1),new r("erns",21,1),new r("at",-1,1),new r("andet",-1,1),new r("het",-1,1),new r("ast",-1,1)],c=[new r("dd",-1,-1),new r("gd",-1,-1),new r("nn",-1,-1),new r("dt",-1,-1),new r("gt",-1,-1),new r("kt",-1,-1),new r("tt",-1,-1)],m=[new r("ig",-1,1),new r("lig",0,1),new r("els",-1,1),new r("fullt",-1,3),new r("löst",-1,2)],l=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,24,0,32],d=[119,127,149],w=new n;this.setCurrent=function(e){w.setCurrent(e)},this.getCurrent=function(){return w.getCurrent()},this.stem=function(){var r=w.cursor;return e(),w.limit_backward=r,w.cursor=w.limit,t(),w.cursor=w.limit,i(),w.cursor=w.limit,s(),!0}};return function(e){return"function"==typeof e.update?e.update(function(e){return t.setCurrent(e),t.stem(),t.getCurrent()}):(t.setCurrent(e),t.stem(),t.getCurrent())}}(),e.Pipeline.registerFunction(e.sv.stemmer,"stemmer-sv"),e.sv.stopWordFilter=e.generateStopWordFilter("alla allt att av blev bli blir blivit de dem den denna deras dess dessa det detta dig din dina ditt du där då efter ej eller en er era ert ett från för ha hade han hans har henne hennes hon honom hur här i icke ingen inom inte jag ju kan kunde man med mellan men mig min mina mitt mot mycket ni nu när någon något några och om oss på samma sedan sig sin sina sitta själv skulle som så sådan sådana sådant till under upp ut utan vad var vara varför varit varje vars vart vem vi vid vilka vilkas vilken vilket vår våra vårt än är åt över".split(" ")),e.Pipeline.registerFunction(e.sv.stopWordFilter,"stopWordFilter-sv")}});
|
||||||
1
assets/javascripts/lunr/min/lunr.ta.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.ta.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.ta=function(){this.pipeline.reset(),this.pipeline.add(e.ta.trimmer,e.ta.stopWordFilter,e.ta.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.ta.stemmer))},e.ta.wordCharacters="-உஊ-ஏஐ-ஙச-ட-னப-யர-ஹ-ிீ-ொ-ௐ---௩௪-௯௰-௹௺-a-zA-Za-zA-Z0-90-9",e.ta.trimmer=e.trimmerSupport.generateTrimmer(e.ta.wordCharacters),e.Pipeline.registerFunction(e.ta.trimmer,"trimmer-ta"),e.ta.stopWordFilter=e.generateStopWordFilter("அங்கு அங்கே அது அதை அந்த அவர் அவர்கள் அவள் அவன் அவை ஆக ஆகவே ஆகையால் ஆதலால் ஆதலினால் ஆனாலும் ஆனால் இங்கு இங்கே இது இதை இந்த இப்படி இவர் இவர்கள் இவள் இவன் இவை இவ்வளவு உனக்கு உனது உன் உன்னால் எங்கு எங்கே எது எதை எந்த எப்படி எவர் எவர்கள் எவள் எவன் எவை எவ்வளவு எனக்கு எனது எனவே என் என்ன என்னால் ஏது ஏன் தனது தன்னால் தானே தான் நாங்கள் நாம் நான் நீ நீங்கள்".split(" ")),e.ta.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var t=e.wordcut;t.init(),e.ta.tokenizer=function(r){if(!arguments.length||null==r||void 0==r)return[];if(Array.isArray(r))return r.map(function(t){return isLunr2?new e.Token(t.toLowerCase()):t.toLowerCase()});var i=r.toString().toLowerCase().replace(/^\s+/,"");return t.cut(i).split("|")},e.Pipeline.registerFunction(e.ta.stemmer,"stemmer-ta"),e.Pipeline.registerFunction(e.ta.stopWordFilter,"stopWordFilter-ta")}});
|
||||||
1
assets/javascripts/lunr/min/lunr.te.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.te.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.te=function(){this.pipeline.reset(),this.pipeline.add(e.te.trimmer,e.te.stopWordFilter,e.te.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.te.stemmer))},e.te.wordCharacters="ఀ-ఄఅ-ఔక-హా-ౌౕ-ౖౘ-ౚౠ-ౡౢ-ౣ౦-౯౸-౿఼ఽ్ౝ౷",e.te.trimmer=e.trimmerSupport.generateTrimmer(e.te.wordCharacters),e.Pipeline.registerFunction(e.te.trimmer,"trimmer-te"),e.te.stopWordFilter=e.generateStopWordFilter("అందరూ అందుబాటులో అడగండి అడగడం అడ్డంగా అనుగుణంగా అనుమతించు అనుమతిస్తుంది అయితే ఇప్పటికే ఉన్నారు ఎక్కడైనా ఎప్పుడు ఎవరైనా ఎవరో ఏ ఏదైనా ఏమైనప్పటికి ఒక ఒకరు కనిపిస్తాయి కాదు కూడా గా గురించి చుట్టూ చేయగలిగింది తగిన తర్వాత దాదాపు దూరంగా నిజంగా పై ప్రకారం ప్రక్కన మధ్య మరియు మరొక మళ్ళీ మాత్రమే మెచ్చుకో వద్ద వెంట వేరుగా వ్యతిరేకంగా సంబంధం".split(" ")),e.te.stemmer=function(){return function(e){return"function"==typeof e.update?e.update(function(e){return e}):e}}();var t=e.wordcut;t.init(),e.te.tokenizer=function(r){if(!arguments.length||null==r||void 0==r)return[];if(Array.isArray(r))return r.map(function(t){return isLunr2?new e.Token(t.toLowerCase()):t.toLowerCase()});var i=r.toString().toLowerCase().replace(/^\s+/,"");return t.cut(i).split("|")},e.Pipeline.registerFunction(e.te.stemmer,"stemmer-te"),e.Pipeline.registerFunction(e.te.stopWordFilter,"stopWordFilter-te")}});
|
||||||
1
assets/javascripts/lunr/min/lunr.th.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.th.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r="2"==e.version[0];e.th=function(){this.pipeline.reset(),this.pipeline.add(e.th.trimmer),r?this.tokenizer=e.th.tokenizer:(e.tokenizer&&(e.tokenizer=e.th.tokenizer),this.tokenizerFn&&(this.tokenizerFn=e.th.tokenizer))},e.th.wordCharacters="[-]",e.th.trimmer=e.trimmerSupport.generateTrimmer(e.th.wordCharacters),e.Pipeline.registerFunction(e.th.trimmer,"trimmer-th");var t=e.wordcut;t.init(),e.th.tokenizer=function(i){if(!arguments.length||null==i||void 0==i)return[];if(Array.isArray(i))return i.map(function(t){return r?new e.Token(t):t});var n=i.toString().replace(/^\s+/,"");return t.cut(n).split("|")}}});
|
||||||
18
assets/javascripts/lunr/min/lunr.tr.min.js
vendored
Normal file
18
assets/javascripts/lunr/min/lunr.tr.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/javascripts/lunr/min/lunr.vi.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.vi.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.vi=function(){this.pipeline.reset(),this.pipeline.add(e.vi.stopWordFilter,e.vi.trimmer)},e.vi.wordCharacters="[A-Za-ẓ̀͐́͑̉̃̓ÂâÊêÔôĂ-ăĐ-đƠ-ơƯ-ư]",e.vi.trimmer=e.trimmerSupport.generateTrimmer(e.vi.wordCharacters),e.Pipeline.registerFunction(e.vi.trimmer,"trimmer-vi"),e.vi.stopWordFilter=e.generateStopWordFilter("là cái nhưng mà".split(" "))}});
|
||||||
1
assets/javascripts/lunr/min/lunr.zh.min.js
vendored
Normal file
1
assets/javascripts/lunr/min/lunr.zh.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r(require("@node-rs/jieba")):r()(e.lunr)}(this,function(e){return function(r,t){if(void 0===r)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===r.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var i="2"==r.version[0];r.zh=function(){this.pipeline.reset(),this.pipeline.add(r.zh.trimmer,r.zh.stopWordFilter,r.zh.stemmer),i?this.tokenizer=r.zh.tokenizer:(r.tokenizer&&(r.tokenizer=r.zh.tokenizer),this.tokenizerFn&&(this.tokenizerFn=r.zh.tokenizer))},r.zh.tokenizer=function(n){if(!arguments.length||null==n||void 0==n)return[];if(Array.isArray(n))return n.map(function(e){return i?new r.Token(e.toLowerCase()):e.toLowerCase()});t&&e.load(t);var o=n.toString().trim().toLowerCase(),s=[];e.cut(o,!0).forEach(function(e){s=s.concat(e.split(" "))}),s=s.filter(function(e){return!!e});var u=0;return s.map(function(e,t){if(i){var n=o.indexOf(e,u),s={};return s.position=[n,e.length],s.index=t,u=n,new r.Token(e,s)}return e})},r.zh.wordCharacters="\\w一-龥",r.zh.trimmer=r.trimmerSupport.generateTrimmer(r.zh.wordCharacters),r.Pipeline.registerFunction(r.zh.trimmer,"trimmer-zh"),r.zh.stemmer=function(){return function(e){return e}}(),r.Pipeline.registerFunction(r.zh.stemmer,"stemmer-zh"),r.zh.stopWordFilter=r.generateStopWordFilter("的 一 不 在 人 有 是 为 為 以 于 於 上 他 而 后 後 之 来 來 及 了 因 下 可 到 由 这 這 与 與 也 此 但 并 並 个 個 其 已 无 無 小 我 们 們 起 最 再 今 去 好 只 又 或 很 亦 某 把 那 你 乃 它 吧 被 比 别 趁 当 當 从 從 得 打 凡 儿 兒 尔 爾 该 該 各 给 給 跟 和 何 还 還 即 几 幾 既 看 据 據 距 靠 啦 另 么 麽 每 嘛 拿 哪 您 凭 憑 且 却 卻 让 讓 仍 啥 如 若 使 谁 誰 虽 雖 随 隨 同 所 她 哇 嗡 往 些 向 沿 哟 喲 用 咱 则 則 怎 曾 至 致 着 著 诸 諸 自".split(" ")),r.Pipeline.registerFunction(r.zh.stopWordFilter,"stopWordFilter-zh")}});
|
||||||
206
assets/javascripts/lunr/tinyseg.js
Normal file
206
assets/javascripts/lunr/tinyseg.js
Normal file
|
|
@ -0,0 +1,206 @@
|
||||||
|
/**
|
||||||
|
* export the module via AMD, CommonJS or as a browser global
|
||||||
|
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
|
||||||
|
*/
|
||||||
|
;(function (root, factory) {
|
||||||
|
if (typeof define === 'function' && define.amd) {
|
||||||
|
// AMD. Register as an anonymous module.
|
||||||
|
define(factory)
|
||||||
|
} else if (typeof exports === 'object') {
|
||||||
|
/**
|
||||||
|
* Node. Does not work with strict CommonJS, but
|
||||||
|
* only CommonJS-like environments that support module.exports,
|
||||||
|
* like Node.
|
||||||
|
*/
|
||||||
|
module.exports = factory()
|
||||||
|
} else {
|
||||||
|
// Browser globals (root is window)
|
||||||
|
factory()(root.lunr);
|
||||||
|
}
|
||||||
|
}(this, function () {
|
||||||
|
/**
|
||||||
|
* Just return a value to define the module export.
|
||||||
|
* This example returns an object, but the module
|
||||||
|
* can return a function as the exported value.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return function(lunr) {
|
||||||
|
// TinySegmenter 0.1 -- Super compact Japanese tokenizer in Javascript
|
||||||
|
// (c) 2008 Taku Kudo <taku@chasen.org>
|
||||||
|
// TinySegmenter is freely distributable under the terms of a new BSD licence.
|
||||||
|
// For details, see http://chasen.org/~taku/software/TinySegmenter/LICENCE.txt
|
||||||
|
|
||||||
|
function TinySegmenter() {
|
||||||
|
var patterns = {
|
||||||
|
"[一二三四五六七八九十百千万億兆]":"M",
|
||||||
|
"[一-龠々〆ヵヶ]":"H",
|
||||||
|
"[ぁ-ん]":"I",
|
||||||
|
"[ァ-ヴーア-ン゙ー]":"K",
|
||||||
|
"[a-zA-Za-zA-Z]":"A",
|
||||||
|
"[0-90-9]":"N"
|
||||||
|
}
|
||||||
|
this.chartype_ = [];
|
||||||
|
for (var i in patterns) {
|
||||||
|
var regexp = new RegExp(i);
|
||||||
|
this.chartype_.push([regexp, patterns[i]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.BIAS__ = -332
|
||||||
|
this.BC1__ = {"HH":6,"II":2461,"KH":406,"OH":-1378};
|
||||||
|
this.BC2__ = {"AA":-3267,"AI":2744,"AN":-878,"HH":-4070,"HM":-1711,"HN":4012,"HO":3761,"IA":1327,"IH":-1184,"II":-1332,"IK":1721,"IO":5492,"KI":3831,"KK":-8741,"MH":-3132,"MK":3334,"OO":-2920};
|
||||||
|
this.BC3__ = {"HH":996,"HI":626,"HK":-721,"HN":-1307,"HO":-836,"IH":-301,"KK":2762,"MK":1079,"MM":4034,"OA":-1652,"OH":266};
|
||||||
|
this.BP1__ = {"BB":295,"OB":304,"OO":-125,"UB":352};
|
||||||
|
this.BP2__ = {"BO":60,"OO":-1762};
|
||||||
|
this.BQ1__ = {"BHH":1150,"BHM":1521,"BII":-1158,"BIM":886,"BMH":1208,"BNH":449,"BOH":-91,"BOO":-2597,"OHI":451,"OIH":-296,"OKA":1851,"OKH":-1020,"OKK":904,"OOO":2965};
|
||||||
|
this.BQ2__ = {"BHH":118,"BHI":-1159,"BHM":466,"BIH":-919,"BKK":-1720,"BKO":864,"OHH":-1139,"OHM":-181,"OIH":153,"UHI":-1146};
|
||||||
|
this.BQ3__ = {"BHH":-792,"BHI":2664,"BII":-299,"BKI":419,"BMH":937,"BMM":8335,"BNN":998,"BOH":775,"OHH":2174,"OHM":439,"OII":280,"OKH":1798,"OKI":-793,"OKO":-2242,"OMH":-2402,"OOO":11699};
|
||||||
|
this.BQ4__ = {"BHH":-3895,"BIH":3761,"BII":-4654,"BIK":1348,"BKK":-1806,"BMI":-3385,"BOO":-12396,"OAH":926,"OHH":266,"OHK":-2036,"ONN":-973};
|
||||||
|
this.BW1__ = {",と":660,",同":727,"B1あ":1404,"B1同":542,"、と":660,"、同":727,"」と":1682,"あっ":1505,"いう":1743,"いっ":-2055,"いる":672,"うし":-4817,"うん":665,"から":3472,"がら":600,"こう":-790,"こと":2083,"こん":-1262,"さら":-4143,"さん":4573,"した":2641,"して":1104,"すで":-3399,"そこ":1977,"それ":-871,"たち":1122,"ため":601,"った":3463,"つい":-802,"てい":805,"てき":1249,"でき":1127,"です":3445,"では":844,"とい":-4915,"とみ":1922,"どこ":3887,"ない":5713,"なっ":3015,"など":7379,"なん":-1113,"にし":2468,"には":1498,"にも":1671,"に対":-912,"の一":-501,"の中":741,"ませ":2448,"まで":1711,"まま":2600,"まる":-2155,"やむ":-1947,"よっ":-2565,"れた":2369,"れで":-913,"をし":1860,"を見":731,"亡く":-1886,"京都":2558,"取り":-2784,"大き":-2604,"大阪":1497,"平方":-2314,"引き":-1336,"日本":-195,"本当":-2423,"毎日":-2113,"目指":-724,"B1あ":1404,"B1同":542,"」と":1682};
|
||||||
|
this.BW2__ = {"..":-11822,"11":-669,"――":-5730,"−−":-13175,"いう":-1609,"うか":2490,"かし":-1350,"かも":-602,"から":-7194,"かれ":4612,"がい":853,"がら":-3198,"きた":1941,"くな":-1597,"こと":-8392,"この":-4193,"させ":4533,"され":13168,"さん":-3977,"しい":-1819,"しか":-545,"した":5078,"して":972,"しな":939,"その":-3744,"たい":-1253,"たた":-662,"ただ":-3857,"たち":-786,"たと":1224,"たは":-939,"った":4589,"って":1647,"っと":-2094,"てい":6144,"てき":3640,"てく":2551,"ては":-3110,"ても":-3065,"でい":2666,"でき":-1528,"でし":-3828,"です":-4761,"でも":-4203,"とい":1890,"とこ":-1746,"とと":-2279,"との":720,"とみ":5168,"とも":-3941,"ない":-2488,"なが":-1313,"など":-6509,"なの":2614,"なん":3099,"にお":-1615,"にし":2748,"にな":2454,"によ":-7236,"に対":-14943,"に従":-4688,"に関":-11388,"のか":2093,"ので":-7059,"のに":-6041,"のの":-6125,"はい":1073,"はが":-1033,"はず":-2532,"ばれ":1813,"まし":-1316,"まで":-6621,"まれ":5409,"めて":-3153,"もい":2230,"もの":-10713,"らか":-944,"らし":-1611,"らに":-1897,"りし":651,"りま":1620,"れた":4270,"れて":849,"れば":4114,"ろう":6067,"われ":7901,"を通":-11877,"んだ":728,"んな":-4115,"一人":602,"一方":-1375,"一日":970,"一部":-1051,"上が":-4479,"会社":-1116,"出て":2163,"分の":-7758,"同党":970,"同日":-913,"大阪":-2471,"委員":-1250,"少な":-1050,"年度":-8669,"年間":-1626,"府県":-2363,"手権":-1982,"新聞":-4066,"日新":-722,"日本":-7068,"日米":3372,"曜日":-601,"朝鮮":-2355,"本人":-2697,"東京":-1543,"然と":-1384,"社会":-1276,"立て":-990,"第に":-1612,"米国":-4268,"11":-669};
|
||||||
|
this.BW3__ = {"あた":-2194,"あり":719,"ある":3846,"い.":-1185,"い。":-1185,"いい":5308,"いえ":2079,"いく":3029,"いた":2056,"いっ":1883,"いる":5600,"いわ":1527,"うち":1117,"うと":4798,"えと":1454,"か.":2857,"か。":2857,"かけ":-743,"かっ":-4098,"かに":-669,"から":6520,"かり":-2670,"が,":1816,"が、":1816,"がき":-4855,"がけ":-1127,"がっ":-913,"がら":-4977,"がり":-2064,"きた":1645,"けど":1374,"こと":7397,"この":1542,"ころ":-2757,"さい":-714,"さを":976,"し,":1557,"し、":1557,"しい":-3714,"した":3562,"して":1449,"しな":2608,"しま":1200,"す.":-1310,"す。":-1310,"する":6521,"ず,":3426,"ず、":3426,"ずに":841,"そう":428,"た.":8875,"た。":8875,"たい":-594,"たの":812,"たり":-1183,"たる":-853,"だ.":4098,"だ。":4098,"だっ":1004,"った":-4748,"って":300,"てい":6240,"てお":855,"ても":302,"です":1437,"でに":-1482,"では":2295,"とう":-1387,"とし":2266,"との":541,"とも":-3543,"どう":4664,"ない":1796,"なく":-903,"など":2135,"に,":-1021,"に、":-1021,"にし":1771,"にな":1906,"には":2644,"の,":-724,"の、":-724,"の子":-1000,"は,":1337,"は、":1337,"べき":2181,"まし":1113,"ます":6943,"まっ":-1549,"まで":6154,"まれ":-793,"らし":1479,"られ":6820,"るる":3818,"れ,":854,"れ、":854,"れた":1850,"れて":1375,"れば":-3246,"れる":1091,"われ":-605,"んだ":606,"んで":798,"カ月":990,"会議":860,"入り":1232,"大会":2217,"始め":1681,"市":965,"新聞":-5055,"日,":974,"日、":974,"社会":2024,"カ月":990};
|
||||||
|
this.TC1__ = {"AAA":1093,"HHH":1029,"HHM":580,"HII":998,"HOH":-390,"HOM":-331,"IHI":1169,"IOH":-142,"IOI":-1015,"IOM":467,"MMH":187,"OOI":-1832};
|
||||||
|
this.TC2__ = {"HHO":2088,"HII":-1023,"HMM":-1154,"IHI":-1965,"KKH":703,"OII":-2649};
|
||||||
|
this.TC3__ = {"AAA":-294,"HHH":346,"HHI":-341,"HII":-1088,"HIK":731,"HOH":-1486,"IHH":128,"IHI":-3041,"IHO":-1935,"IIH":-825,"IIM":-1035,"IOI":-542,"KHH":-1216,"KKA":491,"KKH":-1217,"KOK":-1009,"MHH":-2694,"MHM":-457,"MHO":123,"MMH":-471,"NNH":-1689,"NNO":662,"OHO":-3393};
|
||||||
|
this.TC4__ = {"HHH":-203,"HHI":1344,"HHK":365,"HHM":-122,"HHN":182,"HHO":669,"HIH":804,"HII":679,"HOH":446,"IHH":695,"IHO":-2324,"IIH":321,"III":1497,"IIO":656,"IOO":54,"KAK":4845,"KKA":3386,"KKK":3065,"MHH":-405,"MHI":201,"MMH":-241,"MMM":661,"MOM":841};
|
||||||
|
this.TQ1__ = {"BHHH":-227,"BHHI":316,"BHIH":-132,"BIHH":60,"BIII":1595,"BNHH":-744,"BOHH":225,"BOOO":-908,"OAKK":482,"OHHH":281,"OHIH":249,"OIHI":200,"OIIH":-68};
|
||||||
|
this.TQ2__ = {"BIHH":-1401,"BIII":-1033,"BKAK":-543,"BOOO":-5591};
|
||||||
|
this.TQ3__ = {"BHHH":478,"BHHM":-1073,"BHIH":222,"BHII":-504,"BIIH":-116,"BIII":-105,"BMHI":-863,"BMHM":-464,"BOMH":620,"OHHH":346,"OHHI":1729,"OHII":997,"OHMH":481,"OIHH":623,"OIIH":1344,"OKAK":2792,"OKHH":587,"OKKA":679,"OOHH":110,"OOII":-685};
|
||||||
|
this.TQ4__ = {"BHHH":-721,"BHHM":-3604,"BHII":-966,"BIIH":-607,"BIII":-2181,"OAAA":-2763,"OAKK":180,"OHHH":-294,"OHHI":2446,"OHHO":480,"OHIH":-1573,"OIHH":1935,"OIHI":-493,"OIIH":626,"OIII":-4007,"OKAK":-8156};
|
||||||
|
this.TW1__ = {"につい":-4681,"東京都":2026};
|
||||||
|
this.TW2__ = {"ある程":-2049,"いった":-1256,"ころが":-2434,"しょう":3873,"その後":-4430,"だって":-1049,"ていた":1833,"として":-4657,"ともに":-4517,"もので":1882,"一気に":-792,"初めて":-1512,"同時に":-8097,"大きな":-1255,"対して":-2721,"社会党":-3216};
|
||||||
|
this.TW3__ = {"いただ":-1734,"してい":1314,"として":-4314,"につい":-5483,"にとっ":-5989,"に当た":-6247,"ので,":-727,"ので、":-727,"のもの":-600,"れから":-3752,"十二月":-2287};
|
||||||
|
this.TW4__ = {"いう.":8576,"いう。":8576,"からな":-2348,"してい":2958,"たが,":1516,"たが、":1516,"ている":1538,"という":1349,"ました":5543,"ません":1097,"ようと":-4258,"よると":5865};
|
||||||
|
this.UC1__ = {"A":484,"K":93,"M":645,"O":-505};
|
||||||
|
this.UC2__ = {"A":819,"H":1059,"I":409,"M":3987,"N":5775,"O":646};
|
||||||
|
this.UC3__ = {"A":-1370,"I":2311};
|
||||||
|
this.UC4__ = {"A":-2643,"H":1809,"I":-1032,"K":-3450,"M":3565,"N":3876,"O":6646};
|
||||||
|
this.UC5__ = {"H":313,"I":-1238,"K":-799,"M":539,"O":-831};
|
||||||
|
this.UC6__ = {"H":-506,"I":-253,"K":87,"M":247,"O":-387};
|
||||||
|
this.UP1__ = {"O":-214};
|
||||||
|
this.UP2__ = {"B":69,"O":935};
|
||||||
|
this.UP3__ = {"B":189};
|
||||||
|
this.UQ1__ = {"BH":21,"BI":-12,"BK":-99,"BN":142,"BO":-56,"OH":-95,"OI":477,"OK":410,"OO":-2422};
|
||||||
|
this.UQ2__ = {"BH":216,"BI":113,"OK":1759};
|
||||||
|
this.UQ3__ = {"BA":-479,"BH":42,"BI":1913,"BK":-7198,"BM":3160,"BN":6427,"BO":14761,"OI":-827,"ON":-3212};
|
||||||
|
this.UW1__ = {",":156,"、":156,"「":-463,"あ":-941,"う":-127,"が":-553,"き":121,"こ":505,"で":-201,"と":-547,"ど":-123,"に":-789,"の":-185,"は":-847,"も":-466,"や":-470,"よ":182,"ら":-292,"り":208,"れ":169,"を":-446,"ん":-137,"・":-135,"主":-402,"京":-268,"区":-912,"午":871,"国":-460,"大":561,"委":729,"市":-411,"日":-141,"理":361,"生":-408,"県":-386,"都":-718,"「":-463,"・":-135};
|
||||||
|
this.UW2__ = {",":-829,"、":-829,"〇":892,"「":-645,"」":3145,"あ":-538,"い":505,"う":134,"お":-502,"か":1454,"が":-856,"く":-412,"こ":1141,"さ":878,"ざ":540,"し":1529,"す":-675,"せ":300,"そ":-1011,"た":188,"だ":1837,"つ":-949,"て":-291,"で":-268,"と":-981,"ど":1273,"な":1063,"に":-1764,"の":130,"は":-409,"ひ":-1273,"べ":1261,"ま":600,"も":-1263,"や":-402,"よ":1639,"り":-579,"る":-694,"れ":571,"を":-2516,"ん":2095,"ア":-587,"カ":306,"キ":568,"ッ":831,"三":-758,"不":-2150,"世":-302,"中":-968,"主":-861,"事":492,"人":-123,"会":978,"保":362,"入":548,"初":-3025,"副":-1566,"北":-3414,"区":-422,"大":-1769,"天":-865,"太":-483,"子":-1519,"学":760,"実":1023,"小":-2009,"市":-813,"年":-1060,"強":1067,"手":-1519,"揺":-1033,"政":1522,"文":-1355,"新":-1682,"日":-1815,"明":-1462,"最":-630,"朝":-1843,"本":-1650,"東":-931,"果":-665,"次":-2378,"民":-180,"気":-1740,"理":752,"発":529,"目":-1584,"相":-242,"県":-1165,"立":-763,"第":810,"米":509,"自":-1353,"行":838,"西":-744,"見":-3874,"調":1010,"議":1198,"込":3041,"開":1758,"間":-1257,"「":-645,"」":3145,"ッ":831,"ア":-587,"カ":306,"キ":568};
|
||||||
|
this.UW3__ = {",":4889,"1":-800,"−":-1723,"、":4889,"々":-2311,"〇":5827,"」":2670,"〓":-3573,"あ":-2696,"い":1006,"う":2342,"え":1983,"お":-4864,"か":-1163,"が":3271,"く":1004,"け":388,"げ":401,"こ":-3552,"ご":-3116,"さ":-1058,"し":-395,"す":584,"せ":3685,"そ":-5228,"た":842,"ち":-521,"っ":-1444,"つ":-1081,"て":6167,"で":2318,"と":1691,"ど":-899,"な":-2788,"に":2745,"の":4056,"は":4555,"ひ":-2171,"ふ":-1798,"へ":1199,"ほ":-5516,"ま":-4384,"み":-120,"め":1205,"も":2323,"や":-788,"よ":-202,"ら":727,"り":649,"る":5905,"れ":2773,"わ":-1207,"を":6620,"ん":-518,"ア":551,"グ":1319,"ス":874,"ッ":-1350,"ト":521,"ム":1109,"ル":1591,"ロ":2201,"ン":278,"・":-3794,"一":-1619,"下":-1759,"世":-2087,"両":3815,"中":653,"主":-758,"予":-1193,"二":974,"人":2742,"今":792,"他":1889,"以":-1368,"低":811,"何":4265,"作":-361,"保":-2439,"元":4858,"党":3593,"全":1574,"公":-3030,"六":755,"共":-1880,"円":5807,"再":3095,"分":457,"初":2475,"別":1129,"前":2286,"副":4437,"力":365,"動":-949,"務":-1872,"化":1327,"北":-1038,"区":4646,"千":-2309,"午":-783,"協":-1006,"口":483,"右":1233,"各":3588,"合":-241,"同":3906,"和":-837,"員":4513,"国":642,"型":1389,"場":1219,"外":-241,"妻":2016,"学":-1356,"安":-423,"実":-1008,"家":1078,"小":-513,"少":-3102,"州":1155,"市":3197,"平":-1804,"年":2416,"広":-1030,"府":1605,"度":1452,"建":-2352,"当":-3885,"得":1905,"思":-1291,"性":1822,"戸":-488,"指":-3973,"政":-2013,"教":-1479,"数":3222,"文":-1489,"新":1764,"日":2099,"旧":5792,"昨":-661,"時":-1248,"曜":-951,"最":-937,"月":4125,"期":360,"李":3094,"村":364,"東":-805,"核":5156,"森":2438,"業":484,"氏":2613,"民":-1694,"決":-1073,"法":1868,"海":-495,"無":979,"物":461,"特":-3850,"生":-273,"用":914,"町":1215,"的":7313,"直":-1835,"省":792,"県":6293,"知":-1528,"私":4231,"税":401,"立":-960,"第":1201,"米":7767,"系":3066,"約":3663,"級":1384,"統":-4229,"総":1163,"線":1255,"者":6457,"能":725,"自":-2869,"英":785,"見":1044,"調":-562,"財":-733,"費":1777,"車":1835,"軍":1375,"込":-1504,"通":-1136,"選":-681,"郎":1026,"郡":4404,"部":1200,"金":2163,"長":421,"開":-1432,"間":1302,"関":-1282,"雨":2009,"電":-1045,"非":2066,"駅":1620,"1":-800,"」":2670,"・":-3794,"ッ":-1350,"ア":551,"グ":1319,"ス":874,"ト":521,"ム":1109,"ル":1591,"ロ":2201,"ン":278};
|
||||||
|
this.UW4__ = {",":3930,".":3508,"―":-4841,"、":3930,"。":3508,"〇":4999,"「":1895,"」":3798,"〓":-5156,"あ":4752,"い":-3435,"う":-640,"え":-2514,"お":2405,"か":530,"が":6006,"き":-4482,"ぎ":-3821,"く":-3788,"け":-4376,"げ":-4734,"こ":2255,"ご":1979,"さ":2864,"し":-843,"じ":-2506,"す":-731,"ず":1251,"せ":181,"そ":4091,"た":5034,"だ":5408,"ち":-3654,"っ":-5882,"つ":-1659,"て":3994,"で":7410,"と":4547,"な":5433,"に":6499,"ぬ":1853,"ね":1413,"の":7396,"は":8578,"ば":1940,"ひ":4249,"び":-4134,"ふ":1345,"へ":6665,"べ":-744,"ほ":1464,"ま":1051,"み":-2082,"む":-882,"め":-5046,"も":4169,"ゃ":-2666,"や":2795,"ょ":-1544,"よ":3351,"ら":-2922,"り":-9726,"る":-14896,"れ":-2613,"ろ":-4570,"わ":-1783,"を":13150,"ん":-2352,"カ":2145,"コ":1789,"セ":1287,"ッ":-724,"ト":-403,"メ":-1635,"ラ":-881,"リ":-541,"ル":-856,"ン":-3637,"・":-4371,"ー":-11870,"一":-2069,"中":2210,"予":782,"事":-190,"井":-1768,"人":1036,"以":544,"会":950,"体":-1286,"作":530,"側":4292,"先":601,"党":-2006,"共":-1212,"内":584,"円":788,"初":1347,"前":1623,"副":3879,"力":-302,"動":-740,"務":-2715,"化":776,"区":4517,"協":1013,"参":1555,"合":-1834,"和":-681,"員":-910,"器":-851,"回":1500,"国":-619,"園":-1200,"地":866,"場":-1410,"塁":-2094,"士":-1413,"多":1067,"大":571,"子":-4802,"学":-1397,"定":-1057,"寺":-809,"小":1910,"屋":-1328,"山":-1500,"島":-2056,"川":-2667,"市":2771,"年":374,"庁":-4556,"後":456,"性":553,"感":916,"所":-1566,"支":856,"改":787,"政":2182,"教":704,"文":522,"方":-856,"日":1798,"時":1829,"最":845,"月":-9066,"木":-485,"来":-442,"校":-360,"業":-1043,"氏":5388,"民":-2716,"気":-910,"沢":-939,"済":-543,"物":-735,"率":672,"球":-1267,"生":-1286,"産":-1101,"田":-2900,"町":1826,"的":2586,"目":922,"省":-3485,"県":2997,"空":-867,"立":-2112,"第":788,"米":2937,"系":786,"約":2171,"経":1146,"統":-1169,"総":940,"線":-994,"署":749,"者":2145,"能":-730,"般":-852,"行":-792,"規":792,"警":-1184,"議":-244,"谷":-1000,"賞":730,"車":-1481,"軍":1158,"輪":-1433,"込":-3370,"近":929,"道":-1291,"選":2596,"郎":-4866,"都":1192,"野":-1100,"銀":-2213,"長":357,"間":-2344,"院":-2297,"際":-2604,"電":-878,"領":-1659,"題":-792,"館":-1984,"首":1749,"高":2120,"「":1895,"」":3798,"・":-4371,"ッ":-724,"ー":-11870,"カ":2145,"コ":1789,"セ":1287,"ト":-403,"メ":-1635,"ラ":-881,"リ":-541,"ル":-856,"ン":-3637};
|
||||||
|
this.UW5__ = {",":465,".":-299,"1":-514,"E2":-32768,"]":-2762,"、":465,"。":-299,"「":363,"あ":1655,"い":331,"う":-503,"え":1199,"お":527,"か":647,"が":-421,"き":1624,"ぎ":1971,"く":312,"げ":-983,"さ":-1537,"し":-1371,"す":-852,"だ":-1186,"ち":1093,"っ":52,"つ":921,"て":-18,"で":-850,"と":-127,"ど":1682,"な":-787,"に":-1224,"の":-635,"は":-578,"べ":1001,"み":502,"め":865,"ゃ":3350,"ょ":854,"り":-208,"る":429,"れ":504,"わ":419,"を":-1264,"ん":327,"イ":241,"ル":451,"ン":-343,"中":-871,"京":722,"会":-1153,"党":-654,"務":3519,"区":-901,"告":848,"員":2104,"大":-1296,"学":-548,"定":1785,"嵐":-1304,"市":-2991,"席":921,"年":1763,"思":872,"所":-814,"挙":1618,"新":-1682,"日":218,"月":-4353,"査":932,"格":1356,"機":-1508,"氏":-1347,"田":240,"町":-3912,"的":-3149,"相":1319,"省":-1052,"県":-4003,"研":-997,"社":-278,"空":-813,"統":1955,"者":-2233,"表":663,"語":-1073,"議":1219,"選":-1018,"郎":-368,"長":786,"間":1191,"題":2368,"館":-689,"1":-514,"E2":-32768,"「":363,"イ":241,"ル":451,"ン":-343};
|
||||||
|
this.UW6__ = {",":227,".":808,"1":-270,"E1":306,"、":227,"。":808,"あ":-307,"う":189,"か":241,"が":-73,"く":-121,"こ":-200,"じ":1782,"す":383,"た":-428,"っ":573,"て":-1014,"で":101,"と":-105,"な":-253,"に":-149,"の":-417,"は":-236,"も":-206,"り":187,"る":-135,"を":195,"ル":-673,"ン":-496,"一":-277,"中":201,"件":-800,"会":624,"前":302,"区":1792,"員":-1212,"委":798,"学":-960,"市":887,"広":-695,"後":535,"業":-697,"相":753,"社":-507,"福":974,"空":-822,"者":1811,"連":463,"郎":1082,"1":-270,"E1":306,"ル":-673,"ン":-496};
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
TinySegmenter.prototype.ctype_ = function(str) {
|
||||||
|
for (var i in this.chartype_) {
|
||||||
|
if (str.match(this.chartype_[i][0])) {
|
||||||
|
return this.chartype_[i][1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "O";
|
||||||
|
}
|
||||||
|
|
||||||
|
TinySegmenter.prototype.ts_ = function(v) {
|
||||||
|
if (v) { return v; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TinySegmenter.prototype.segment = function(input) {
|
||||||
|
if (input == null || input == undefined || input == "") {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
var result = [];
|
||||||
|
var seg = ["B3","B2","B1"];
|
||||||
|
var ctype = ["O","O","O"];
|
||||||
|
var o = input.split("");
|
||||||
|
for (i = 0; i < o.length; ++i) {
|
||||||
|
seg.push(o[i]);
|
||||||
|
ctype.push(this.ctype_(o[i]))
|
||||||
|
}
|
||||||
|
seg.push("E1");
|
||||||
|
seg.push("E2");
|
||||||
|
seg.push("E3");
|
||||||
|
ctype.push("O");
|
||||||
|
ctype.push("O");
|
||||||
|
ctype.push("O");
|
||||||
|
var word = seg[3];
|
||||||
|
var p1 = "U";
|
||||||
|
var p2 = "U";
|
||||||
|
var p3 = "U";
|
||||||
|
for (var i = 4; i < seg.length - 3; ++i) {
|
||||||
|
var score = this.BIAS__;
|
||||||
|
var w1 = seg[i-3];
|
||||||
|
var w2 = seg[i-2];
|
||||||
|
var w3 = seg[i-1];
|
||||||
|
var w4 = seg[i];
|
||||||
|
var w5 = seg[i+1];
|
||||||
|
var w6 = seg[i+2];
|
||||||
|
var c1 = ctype[i-3];
|
||||||
|
var c2 = ctype[i-2];
|
||||||
|
var c3 = ctype[i-1];
|
||||||
|
var c4 = ctype[i];
|
||||||
|
var c5 = ctype[i+1];
|
||||||
|
var c6 = ctype[i+2];
|
||||||
|
score += this.ts_(this.UP1__[p1]);
|
||||||
|
score += this.ts_(this.UP2__[p2]);
|
||||||
|
score += this.ts_(this.UP3__[p3]);
|
||||||
|
score += this.ts_(this.BP1__[p1 + p2]);
|
||||||
|
score += this.ts_(this.BP2__[p2 + p3]);
|
||||||
|
score += this.ts_(this.UW1__[w1]);
|
||||||
|
score += this.ts_(this.UW2__[w2]);
|
||||||
|
score += this.ts_(this.UW3__[w3]);
|
||||||
|
score += this.ts_(this.UW4__[w4]);
|
||||||
|
score += this.ts_(this.UW5__[w5]);
|
||||||
|
score += this.ts_(this.UW6__[w6]);
|
||||||
|
score += this.ts_(this.BW1__[w2 + w3]);
|
||||||
|
score += this.ts_(this.BW2__[w3 + w4]);
|
||||||
|
score += this.ts_(this.BW3__[w4 + w5]);
|
||||||
|
score += this.ts_(this.TW1__[w1 + w2 + w3]);
|
||||||
|
score += this.ts_(this.TW2__[w2 + w3 + w4]);
|
||||||
|
score += this.ts_(this.TW3__[w3 + w4 + w5]);
|
||||||
|
score += this.ts_(this.TW4__[w4 + w5 + w6]);
|
||||||
|
score += this.ts_(this.UC1__[c1]);
|
||||||
|
score += this.ts_(this.UC2__[c2]);
|
||||||
|
score += this.ts_(this.UC3__[c3]);
|
||||||
|
score += this.ts_(this.UC4__[c4]);
|
||||||
|
score += this.ts_(this.UC5__[c5]);
|
||||||
|
score += this.ts_(this.UC6__[c6]);
|
||||||
|
score += this.ts_(this.BC1__[c2 + c3]);
|
||||||
|
score += this.ts_(this.BC2__[c3 + c4]);
|
||||||
|
score += this.ts_(this.BC3__[c4 + c5]);
|
||||||
|
score += this.ts_(this.TC1__[c1 + c2 + c3]);
|
||||||
|
score += this.ts_(this.TC2__[c2 + c3 + c4]);
|
||||||
|
score += this.ts_(this.TC3__[c3 + c4 + c5]);
|
||||||
|
score += this.ts_(this.TC4__[c4 + c5 + c6]);
|
||||||
|
// score += this.ts_(this.TC5__[c4 + c5 + c6]);
|
||||||
|
score += this.ts_(this.UQ1__[p1 + c1]);
|
||||||
|
score += this.ts_(this.UQ2__[p2 + c2]);
|
||||||
|
score += this.ts_(this.UQ3__[p3 + c3]);
|
||||||
|
score += this.ts_(this.BQ1__[p2 + c2 + c3]);
|
||||||
|
score += this.ts_(this.BQ2__[p2 + c3 + c4]);
|
||||||
|
score += this.ts_(this.BQ3__[p3 + c2 + c3]);
|
||||||
|
score += this.ts_(this.BQ4__[p3 + c3 + c4]);
|
||||||
|
score += this.ts_(this.TQ1__[p2 + c1 + c2 + c3]);
|
||||||
|
score += this.ts_(this.TQ2__[p2 + c2 + c3 + c4]);
|
||||||
|
score += this.ts_(this.TQ3__[p3 + c1 + c2 + c3]);
|
||||||
|
score += this.ts_(this.TQ4__[p3 + c2 + c3 + c4]);
|
||||||
|
var p = "O";
|
||||||
|
if (score > 0) {
|
||||||
|
result.push(word);
|
||||||
|
word = "";
|
||||||
|
p = "B";
|
||||||
|
}
|
||||||
|
p1 = p2;
|
||||||
|
p2 = p3;
|
||||||
|
p3 = p;
|
||||||
|
word += seg[i];
|
||||||
|
}
|
||||||
|
result.push(word);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
lunr.TinySegmenter = TinySegmenter;
|
||||||
|
};
|
||||||
|
|
||||||
|
}));
|
||||||
6708
assets/javascripts/lunr/wordcut.js
Normal file
6708
assets/javascripts/lunr/wordcut.js
Normal file
File diff suppressed because one or more lines are too long
42
assets/javascripts/workers/search.973d3a69.min.js
vendored
Normal file
42
assets/javascripts/workers/search.973d3a69.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
assets/javascripts/workers/search.973d3a69.min.js.map
Normal file
7
assets/javascripts/workers/search.973d3a69.min.js.map
Normal file
File diff suppressed because one or more lines are too long
1
assets/stylesheets/main.84d31ad4.min.css
vendored
Normal file
1
assets/stylesheets/main.84d31ad4.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/stylesheets/main.84d31ad4.min.css.map
Normal file
1
assets/stylesheets/main.84d31ad4.min.css.map
Normal file
File diff suppressed because one or more lines are too long
1
assets/stylesheets/palette.06af60db.min.css
vendored
Normal file
1
assets/stylesheets/palette.06af60db.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
assets/stylesheets/palette.06af60db.min.css.map
Normal file
1
assets/stylesheets/palette.06af60db.min.css.map
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"sources":["src/templates/assets/stylesheets/palette/_scheme.scss","../../../../src/templates/assets/stylesheets/palette.scss","src/templates/assets/stylesheets/palette/_accent.scss","src/templates/assets/stylesheets/palette/_primary.scss","src/templates/assets/stylesheets/utilities/_break.scss"],"names":[],"mappings":"AA2BA,cAGE,6BAME,sDAAA,CACA,6DAAA,CACA,+DAAA,CACA,gEAAA,CACA,mDAAA,CACA,6DAAA,CACA,+DAAA,CACA,gEAAA,CAGA,mDAAA,CACA,gDAAA,CAGA,0BAAA,CACA,mCAAA,CAGA,iCAAA,CACA,kCAAA,CACA,mCAAA,CACA,mCAAA,CACA,kCAAA,CACA,iCAAA,CACA,+CAAA,CACA,6DAAA,CACA,gEAAA,CACA,4DAAA,CACA,4DAAA,CACA,6DAAA,CAGA,6CAAA,CAGA,+CAAA,CAGA,uDAAA,CACA,6DAAA,CACA,2DAAA,CAGA,iCAAA,CAGA,yDAAA,CACA,iEAAA,CAGA,mDAAA,CACA,mDAAA,CAGA,qDAAA,CACA,uDAAA,CAGA,8DAAA,CAKA,8DAAA,CAKA,0DAAA,CAvEA,iBCeF,CD6DE,kHAEE,YC3DJ,CDkFE,yDACE,4BChFJ,CD+EE,2DACE,4BC7EJ,CD4EE,gEACE,4BC1EJ,CDyEE,2DACE,4BCvEJ,CDsEE,yDACE,4BCpEJ,CDmEE,0DACE,4BCjEJ,CDgEE,gEACE,4BC9DJ,CD6DE,0DACE,4BC3DJ,CD0DE,2OACE,4BC/CJ,CDsDA,+FAGE,iCCpDF,CACF,CC/CE,2BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCD2CN,CCrDE,4BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDkDN,CC5DE,8BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDyDN,CCnEE,mCACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDgEN,CC1EE,8BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDuEN,CCjFE,4BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCD8EN,CCxFE,kCACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDqFN,CC/FE,4BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCD4FN,CCtGE,4BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDmGN,CC7GE,6BACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCD0GN,CCpHE,mCACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDiHN,CC3HE,4BACE,4BAAA,CACA,2CAAA,CAIE,8BAAA,CACA,qCD2HN,CClIE,8BACE,4BAAA,CACA,2CAAA,CAIE,8BAAA,CACA,qCDkIN,CCzIE,6BACE,yBAAA,CACA,2CAAA,CAIE,8BAAA,CACA,qCDyIN,CChJE,8BACE,4BAAA,CACA,2CAAA,CAIE,8BAAA,CACA,qCDgJN,CCvJE,mCACE,4BAAA,CACA,2CAAA,CAOE,yBAAA,CACA,qCDoJN,CEzJE,4BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsJN,CEjKE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8JN,CEzKE,+BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsKN,CEjLE,oCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8KN,CEzLE,+BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsLN,CEjME,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8LN,CEzME,mCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsMN,CEjNE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8MN,CEzNE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsNN,CEjOE,8BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8NN,CEzOE,oCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsON,CEjPE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAIE,+BAAA,CACA,sCFiPN,CEzPE,+BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAIE,+BAAA,CACA,sCFyPN,CEjQE,8BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAIE,+BAAA,CACA,sCFiQN,CEzQE,+BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAIE,+BAAA,CACA,sCFyQN,CEjRE,oCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCF8QN,CEzRE,8BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCFsRN,CEjSE,6BACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCAAA,CAKA,4BF0RN,CE1SE,kCACE,6BAAA,CACA,oCAAA,CACA,mCAAA,CAOE,0BAAA,CACA,sCAAA,CAKA,4BFmSN,CEpRE,sEACE,4BFuRJ,CExRE,+DACE,4BF2RJ,CE5RE,iEACE,4BF+RJ,CEhSE,gEACE,4BFmSJ,CEpSE,iEACE,4BFuSJ,CE9RA,8BACE,mDAAA,CACA,4DAAA,CACA,0DAAA,CACA,oDAAA,CACA,2DAAA,CAGA,4BF+RF,CE5RE,yCACE,+BF8RJ,CE3RI,kDAEE,0CAAA,CACA,sCAAA,CAFA,mCF+RN,CG3MI,mCD1EA,+CACE,8CFwRJ,CErRI,qDACE,8CFuRN,CElRE,iEACE,mCFoRJ,CACF,CGtNI,sCDvDA,uCACE,oCFgRJ,CACF,CEvQA,8BACE,kDAAA,CACA,4DAAA,CACA,wDAAA,CACA,oDAAA,CACA,6DAAA,CAGA,4BFwQF,CErQE,yCACE,+BFuQJ,CEpQI,kDAEE,0CAAA,CACA,sCAAA,CAFA,mCFwQN,CEjQE,yCACE,6CFmQJ,CG5NI,0CDhCA,8CACE,gDF+PJ,CACF,CGjOI,0CDvBA,iFACE,6CF2PJ,CACF,CGzPI,sCDKA,uCACE,6CFuPJ,CACF","file":"palette.css"}
|
||||||
525
checksums/index.html
Normal file
525
checksums/index.html
Normal file
|
|
@ -0,0 +1,525 @@
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en" class="no-js">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="prev" href="../hashing/">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="next" href="../rsa/">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="icon" href="../assets/images/favicon.png">
|
||||||
|
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.23">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<title>Checksums - Enchantrix</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../assets/stylesheets/main.84d31ad4.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||||
|
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<body dir="ltr">
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||||
|
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||||
|
<label class="md-overlay" for="__drawer"></label>
|
||||||
|
<div data-md-component="skip">
|
||||||
|
|
||||||
|
|
||||||
|
<a href="#checksums" class="md-skip">
|
||||||
|
Skip to content
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div data-md-component="announce">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<header class="md-header md-header--shadow" data-md-component="header">
|
||||||
|
<nav class="md-header__inner md-grid" aria-label="Header">
|
||||||
|
<a href=".." title="Enchantrix" class="md-header__button md-logo" aria-label="Enchantrix" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
<label class="md-header__button md-icon" for="__drawer">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-header__title" data-md-component="header-title">
|
||||||
|
<div class="md-header__ellipsis">
|
||||||
|
<div class="md-header__topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Enchantrix
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="md-header__topic" data-md-component="header-topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
|
||||||
|
Checksums
|
||||||
|
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" for="__search">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
|
<label class="md-search__overlay" for="__search"></label>
|
||||||
|
<div class="md-search__inner" role="search">
|
||||||
|
<form class="md-search__form" name="search">
|
||||||
|
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
|
||||||
|
<label class="md-search__icon md-icon" for="__search">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
|
||||||
|
</label>
|
||||||
|
<nav class="md-search__options" aria-label="Search">
|
||||||
|
|
||||||
|
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<div class="md-search__output">
|
||||||
|
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
|
||||||
|
<div class="md-search-result" data-md-component="search-result">
|
||||||
|
<div class="md-search-result__meta">
|
||||||
|
Initializing search
|
||||||
|
</div>
|
||||||
|
<ol class="md-search-result__list" role="presentation"></ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="md-container" data-md-component="container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<main class="md-main" data-md-component="main">
|
||||||
|
<div class="md-main__inner md-grid">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
|
||||||
|
<label class="md-nav__title" for="__drawer">
|
||||||
|
<a href=".." title="Enchantrix" class="md-nav__button md-logo" aria-label="Enchantrix" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
Enchantrix
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href=".." class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Home
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../trix_format/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix File Format
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" checked>
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Examples
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="true">
|
||||||
|
<label class="md-nav__title" for="__nav_3">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Examples
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../trix_and_sigils/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix & Sigil Chaining
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../hashing/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Hashing
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--active">
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="./" class="md-nav__link md-nav__link--active">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Checksums
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../rsa/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
RSA
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../standalone_sigils/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Standalone Sigils
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-content" data-md-component="content">
|
||||||
|
<article class="md-content__inner md-typeset">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h1 id="checksums">Checksums</h1>
|
||||||
|
<p>This example demonstrates how to use the <code>crypt</code> service to calculate checksums using various algorithms.</p>
|
||||||
|
<pre><code class="language-go">package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Snider/Enchantrix/pkg/crypt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func demoChecksums() {
|
||||||
|
fmt.Println("--- Checksum Demo ---")
|
||||||
|
cryptService := crypt.NewService()
|
||||||
|
|
||||||
|
// Luhn
|
||||||
|
luhnPayloadGood := "49927398716"
|
||||||
|
luhnPayloadBad := "49927398717"
|
||||||
|
fmt.Printf("Luhn Checksum:\n")
|
||||||
|
fmt.Printf(" - Payload '%s' is valid: %v\n", luhnPayloadGood, cryptService.Luhn(luhnPayloadGood))
|
||||||
|
fmt.Printf(" - Payload '%s' is valid: %v\n", luhnPayloadBad, cryptService.Luhn(luhnPayloadBad))
|
||||||
|
|
||||||
|
// Fletcher
|
||||||
|
fletcherPayload := "abcde"
|
||||||
|
fmt.Printf("\nFletcher Checksums (Payload: \"%s\"):\n", fletcherPayload)
|
||||||
|
fmt.Printf(" - Fletcher16: %d\n", cryptService.Fletcher16(fletcherPayload))
|
||||||
|
fmt.Printf(" - Fletcher32: %d\n", cryptService.Fletcher32(fletcherPayload))
|
||||||
|
fmt.Printf(" - Fletcher64: %d\n", cryptService.Fletcher64(fletcherPayload))
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="md-footer">
|
||||||
|
|
||||||
|
<div class="md-footer-meta md-typeset">
|
||||||
|
<div class="md-footer-meta__inner md-grid">
|
||||||
|
<div class="md-copyright">
|
||||||
|
|
||||||
|
|
||||||
|
Made with
|
||||||
|
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||||
|
Material for MkDocs
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="md-dialog" data-md-component="dialog">
|
||||||
|
<div class="md-dialog__inner md-typeset"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script id="__config" type="application/json">{"base": "..", "features": [], "search": "../assets/javascripts/workers/search.973d3a69.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="../assets/javascripts/bundle.f55a23d4.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
227
cmd/trix/main.go
227
cmd/trix/main.go
|
|
@ -1,227 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/enchantrix"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/trix"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
rootCmd = &cobra.Command{
|
|
||||||
Use: "trix",
|
|
||||||
Short: "A tool for encoding and decoding .trix files",
|
|
||||||
Long: `trix is a command-line tool for working with the .trix file format, which is used for storing encrypted data.`,
|
|
||||||
}
|
|
||||||
|
|
||||||
encodeCmd = &cobra.Command{
|
|
||||||
Use: "encode",
|
|
||||||
Short: "Encode a file to the .trix format",
|
|
||||||
RunE: runEncode,
|
|
||||||
}
|
|
||||||
|
|
||||||
decodeCmd = &cobra.Command{
|
|
||||||
Use: "decode",
|
|
||||||
Short: "Decode a .trix file",
|
|
||||||
RunE: runDecode,
|
|
||||||
}
|
|
||||||
|
|
||||||
hashCmd = &cobra.Command{
|
|
||||||
Use: "hash [algorithm]",
|
|
||||||
Short: "Hash a file using a specified algorithm",
|
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
RunE: runHash,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var availableSigils = []string{
|
|
||||||
"reverse", "hex", "base64", "gzip", "json", "json-indent", "md4", "md5",
|
|
||||||
"sha1", "sha224", "sha256", "sha384", "sha512", "ripemd160", "sha3-224",
|
|
||||||
"sha3-256", "sha3-384", "sha3-512", "sha512-224", "sha512-256",
|
|
||||||
"blake2s-256", "blake2b-256", "blake2b-384", "blake2b-512",
|
|
||||||
}
|
|
||||||
|
|
||||||
var exit = os.Exit
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Add flags to encode command
|
|
||||||
encodeCmd.Flags().StringP("input", "i", "", "Input file (or stdin)")
|
|
||||||
encodeCmd.Flags().StringP("output", "o", "", "Output file")
|
|
||||||
encodeCmd.Flags().StringP("magic", "m", "", "Magic number (4 bytes)")
|
|
||||||
|
|
||||||
// Add flags to decode command
|
|
||||||
decodeCmd.Flags().StringP("input", "i", "", "Input file (or stdin)")
|
|
||||||
decodeCmd.Flags().StringP("output", "o", "", "Output file")
|
|
||||||
decodeCmd.Flags().StringP("magic", "m", "", "Magic number (4 bytes)")
|
|
||||||
|
|
||||||
// Add flags to hash command
|
|
||||||
hashCmd.Flags().StringP("input", "i", "", "Input file (or stdin)")
|
|
||||||
|
|
||||||
rootCmd.AddCommand(encodeCmd, decodeCmd, hashCmd)
|
|
||||||
|
|
||||||
// Add sigil commands
|
|
||||||
for _, sigilName := range availableSigils {
|
|
||||||
sigilCmd := &cobra.Command{
|
|
||||||
Use: sigilName,
|
|
||||||
Short: "Apply the " + sigilName + " sigil",
|
|
||||||
RunE: createSigilRunE(sigilName),
|
|
||||||
}
|
|
||||||
sigilCmd.Flags().StringP("input", "i", "-", "Input file or string (or stdin)")
|
|
||||||
rootCmd.AddCommand(sigilCmd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func createSigilRunE(sigilName string) func(cmd *cobra.Command, args []string) error {
|
|
||||||
return func(cmd *cobra.Command, args []string) error {
|
|
||||||
input, _ := cmd.Flags().GetString("input")
|
|
||||||
return handleSigil(cmd, sigilName, input)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
|
||||||
exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func runEncode(cmd *cobra.Command, args []string) error {
|
|
||||||
input, _ := cmd.Flags().GetString("input")
|
|
||||||
output, _ := cmd.Flags().GetString("output")
|
|
||||||
magic, _ := cmd.Flags().GetString("magic")
|
|
||||||
return handleEncode(cmd, input, output, magic, args)
|
|
||||||
}
|
|
||||||
|
|
||||||
func runDecode(cmd *cobra.Command, args []string) error {
|
|
||||||
input, _ := cmd.Flags().GetString("input")
|
|
||||||
output, _ := cmd.Flags().GetString("output")
|
|
||||||
magic, _ := cmd.Flags().GetString("magic")
|
|
||||||
return handleDecode(cmd, input, output, magic, args)
|
|
||||||
}
|
|
||||||
|
|
||||||
func runHash(cmd *cobra.Command, args []string) error {
|
|
||||||
input, _ := cmd.Flags().GetString("input")
|
|
||||||
return handleHash(cmd, input, args[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleSigil(cmd *cobra.Command, sigilName, input string) error {
|
|
||||||
s, err := enchantrix.NewSigil(sigilName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var data []byte
|
|
||||||
if input == "-" {
|
|
||||||
data, err = ioutil.ReadAll(cmd.InOrStdin())
|
|
||||||
} else if _, err := os.Stat(input); err == nil {
|
|
||||||
data, err = ioutil.ReadFile(input)
|
|
||||||
} else {
|
|
||||||
data = []byte(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := s.In(data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
cmd.OutOrStdout().Write(out)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleHash(cmd *cobra.Command, inputFile, algo string) error {
|
|
||||||
if algo == "" {
|
|
||||||
return fmt.Errorf("hash algorithm is required")
|
|
||||||
}
|
|
||||||
service := crypt.NewService()
|
|
||||||
if !service.IsHashAlgo(algo) {
|
|
||||||
return fmt.Errorf("invalid hash algorithm: %s", algo)
|
|
||||||
}
|
|
||||||
|
|
||||||
var data []byte
|
|
||||||
var err error
|
|
||||||
if inputFile == "" || inputFile == "-" {
|
|
||||||
data, err = ioutil.ReadAll(cmd.InOrStdin())
|
|
||||||
} else {
|
|
||||||
data, err = ioutil.ReadFile(inputFile)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
hash := service.Hash(crypt.HashType(algo), string(data))
|
|
||||||
cmd.OutOrStdout().Write([]byte(hash))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleEncode(cmd *cobra.Command, inputFile, outputFile, magicNumber string, sigils []string) error {
|
|
||||||
if len(magicNumber) != 4 {
|
|
||||||
return fmt.Errorf("magic number must be 4 bytes long")
|
|
||||||
}
|
|
||||||
var data []byte
|
|
||||||
var err error
|
|
||||||
if inputFile == "" || inputFile == "-" {
|
|
||||||
data, err = ioutil.ReadAll(cmd.InOrStdin())
|
|
||||||
} else {
|
|
||||||
data, err = ioutil.ReadFile(inputFile)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
t := &trix.Trix{
|
|
||||||
Header: make(map[string]interface{}),
|
|
||||||
Payload: data,
|
|
||||||
InSigils: sigils,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := t.Pack(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
encoded, err := trix.Encode(t, magicNumber, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if outputFile == "" || outputFile == "-" {
|
|
||||||
_, err = cmd.OutOrStdout().Write(encoded)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return ioutil.WriteFile(outputFile, encoded, 0644)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleDecode(cmd *cobra.Command, inputFile, outputFile, magicNumber string, sigils []string) error {
|
|
||||||
if len(magicNumber) != 4 {
|
|
||||||
return fmt.Errorf("magic number must be 4 bytes long")
|
|
||||||
}
|
|
||||||
var data []byte
|
|
||||||
var err error
|
|
||||||
if inputFile == "" || inputFile == "-" {
|
|
||||||
data, err = ioutil.ReadAll(cmd.InOrStdin())
|
|
||||||
} else {
|
|
||||||
data, err = ioutil.ReadFile(inputFile)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t, err := trix.Decode(data, magicNumber, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.OutSigils = sigils
|
|
||||||
if err := t.Unpack(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if outputFile == "" || outputFile == "-" {
|
|
||||||
_, err = cmd.OutOrStdout().Write(t.Payload)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return ioutil.WriteFile(outputFile, t.Payload, 0644)
|
|
||||||
}
|
|
||||||
|
|
@ -1,149 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMain_Good(t *testing.T) {
|
|
||||||
// Redirect stdout to a buffer
|
|
||||||
old := os.Stdout
|
|
||||||
r, w, _ := os.Pipe()
|
|
||||||
os.Stdout = w
|
|
||||||
|
|
||||||
// Run the main function
|
|
||||||
main()
|
|
||||||
|
|
||||||
// Restore stdout
|
|
||||||
w.Close()
|
|
||||||
os.Stdout = old
|
|
||||||
|
|
||||||
// Read the output from the buffer
|
|
||||||
var buf bytes.Buffer
|
|
||||||
io.Copy(&buf, r)
|
|
||||||
|
|
||||||
// Check that the output contains the help message
|
|
||||||
assert.Contains(t, buf.String(), "Usage:")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMain_Bad(t *testing.T) {
|
|
||||||
oldExit := exit
|
|
||||||
defer func() { exit = oldExit }()
|
|
||||||
var exitCode int
|
|
||||||
exit = func(code int) {
|
|
||||||
exitCode = code
|
|
||||||
}
|
|
||||||
rootCmd.RunE = func(cmd *cobra.Command, args []string) error {
|
|
||||||
return errors.New("test error")
|
|
||||||
}
|
|
||||||
// The rootCmd needs to be reset so that the test can be run again
|
|
||||||
defer func() { rootCmd = &cobra.Command{
|
|
||||||
Use: "trix",
|
|
||||||
Short: "A tool for encoding and decoding .trix files",
|
|
||||||
Long: `trix is a command-line tool for working with the .trix file format, which is used for storing encrypted data.`,
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
main()
|
|
||||||
assert.Equal(t, 1, exitCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHandleSigil_Good(t *testing.T) {
|
|
||||||
// Create a dummy command
|
|
||||||
cmd := &cobra.Command{}
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
cmd.SetOut(buf)
|
|
||||||
|
|
||||||
// Run the handleSigil function
|
|
||||||
err := handleSigil(cmd, "base64", "hello")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// Check that the output is the base64 encoded string
|
|
||||||
assert.Equal(t, "aGVsbG8=", strings.TrimSpace(buf.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHandleSigil_Bad(t *testing.T) {
|
|
||||||
cmd := &cobra.Command{}
|
|
||||||
err := handleSigil(cmd, "bad-sigil", "hello")
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunEncodeAndDecode_Good(t *testing.T) {
|
|
||||||
// Encode
|
|
||||||
encodeCmd := &cobra.Command{}
|
|
||||||
encodeBuf := new(bytes.Buffer)
|
|
||||||
encodeCmd.SetOut(encodeBuf)
|
|
||||||
encodeCmd.SetIn(strings.NewReader("hello"))
|
|
||||||
encodeCmd.Flags().StringP("input", "i", "-", "Input file or string (or stdin)")
|
|
||||||
encodeCmd.Flags().StringP("output", "o", "-", "Output file")
|
|
||||||
encodeCmd.Flags().StringP("magic", "m", "TEST", "Magic number (4 bytes)")
|
|
||||||
err := runEncode(encodeCmd, []string{"base64"})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotEmpty(t, encodeBuf.String())
|
|
||||||
|
|
||||||
// Decode
|
|
||||||
decodeCmd := &cobra.Command{}
|
|
||||||
decodeBuf := new(bytes.Buffer)
|
|
||||||
decodeCmd.SetOut(decodeBuf)
|
|
||||||
decodeCmd.SetIn(encodeBuf) // Use the output of the encode as the input for the decode
|
|
||||||
decodeCmd.Flags().StringP("input", "i", "-", "Input file or string (or stdin)")
|
|
||||||
decodeCmd.Flags().StringP("output", "o", "-", "Output file")
|
|
||||||
decodeCmd.Flags().StringP("magic", "m", "TEST", "Magic number (4 bytes)")
|
|
||||||
err = runDecode(decodeCmd, []string{"base64"})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "hello", strings.TrimSpace(decodeBuf.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunEncode_Bad(t *testing.T) {
|
|
||||||
cmd := &cobra.Command{}
|
|
||||||
cmd.Flags().StringP("magic", "m", "bad", "Magic number (4 bytes)")
|
|
||||||
err := runEncode(cmd, []string{})
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunDecode_Bad(t *testing.T) {
|
|
||||||
cmd := &cobra.Command{}
|
|
||||||
cmd.Flags().StringP("magic", "m", "bad", "Magic number (4 bytes)")
|
|
||||||
err := runDecode(cmd, []string{})
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunHash_Good(t *testing.T) {
|
|
||||||
cmd := &cobra.Command{}
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
cmd.SetOut(buf)
|
|
||||||
cmd.SetIn(strings.NewReader("hello"))
|
|
||||||
cmd.Flags().StringP("input", "i", "-", "Input file or string (or stdin)")
|
|
||||||
|
|
||||||
// Run the runHash function
|
|
||||||
err := runHash(cmd, []string{"sha256"})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// Check that the output is not empty
|
|
||||||
assert.NotEmpty(t, buf.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunHash_Bad(t *testing.T) {
|
|
||||||
cmd := &cobra.Command{}
|
|
||||||
err := runHash(cmd, []string{"bad-hash"})
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateSigilRunE_Good(t *testing.T) {
|
|
||||||
cmd := &cobra.Command{}
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
cmd.SetOut(buf)
|
|
||||||
cmd.SetIn(strings.NewReader("hello"))
|
|
||||||
cmd.Flags().StringP("input", "i", "-", "Input file or string (or stdin)")
|
|
||||||
|
|
||||||
// Run the createSigilRunE function
|
|
||||||
runE := createSigilRunE("base64")
|
|
||||||
err := runE(cmd, []string{})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
# Checksums
|
|
||||||
|
|
||||||
This example demonstrates how to use the `crypt` service to calculate checksums using various algorithms.
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func demoChecksums() {
|
|
||||||
fmt.Println("--- Checksum Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// Luhn
|
|
||||||
luhnPayloadGood := "49927398716"
|
|
||||||
luhnPayloadBad := "49927398717"
|
|
||||||
fmt.Printf("Luhn Checksum:\n")
|
|
||||||
fmt.Printf(" - Payload '%s' is valid: %v\n", luhnPayloadGood, cryptService.Luhn(luhnPayloadGood))
|
|
||||||
fmt.Printf(" - Payload '%s' is valid: %v\n", luhnPayloadBad, cryptService.Luhn(luhnPayloadBad))
|
|
||||||
|
|
||||||
// Fletcher
|
|
||||||
fletcherPayload := "abcde"
|
|
||||||
fmt.Printf("\nFletcher Checksums (Payload: \"%s\"):\n", fletcherPayload)
|
|
||||||
fmt.Printf(" - Fletcher16: %d\n", cryptService.Fletcher16(fletcherPayload))
|
|
||||||
fmt.Printf(" - Fletcher32: %d\n", cryptService.Fletcher32(fletcherPayload))
|
|
||||||
fmt.Printf(" - Fletcher64: %d\n", cryptService.Fletcher64(fletcherPayload))
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
```
|
|
||||||
116
docs/cli.md
116
docs/cli.md
|
|
@ -1,116 +0,0 @@
|
||||||
# CLI Reference
|
|
||||||
|
|
||||||
The `trix` command-line tool allows you to work with `.trix` files, apply sigils, and perform hashing operations directly from the terminal.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```bash
|
|
||||||
trix [command]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Global Flags
|
|
||||||
|
|
||||||
* `--help`: Show help for command.
|
|
||||||
|
|
||||||
## Commands
|
|
||||||
|
|
||||||
### `encode`
|
|
||||||
|
|
||||||
Encodes data into the `.trix` file format.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
trix encode [flags] [sigils...]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Flags:**
|
|
||||||
|
|
||||||
* `-i, --input string`: Input file path. If not specified, reads from stdin.
|
|
||||||
* `-o, --output string`: Output file path. If not specified, writes to stdout.
|
|
||||||
* `-m, --magic string`: Custom 4-byte magic number (e.g., `TRIX`).
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Encode a file, apply gzip and base64 sigils, and save to output.trix
|
|
||||||
trix encode -i data.json -o output.trix -m TRIX gzip base64
|
|
||||||
```
|
|
||||||
|
|
||||||
### `decode`
|
|
||||||
|
|
||||||
Decodes a `.trix` file.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
trix decode [flags] [sigils...]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Flags:**
|
|
||||||
|
|
||||||
* `-i, --input string`: Input file path. If not specified, reads from stdin.
|
|
||||||
* `-o, --output string`: Output file path. If not specified, writes to stdout.
|
|
||||||
* `-m, --magic string`: Custom 4-byte magic number.
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Decode a file, reversing the base64 and gzip sigils implicitly if stored in header,
|
|
||||||
# or explicit sigils can be passed if needed for unpacking steps not in header (though unlikely for standard use).
|
|
||||||
# Typically:
|
|
||||||
trix decode -i output.trix -o restored.json -m TRIX
|
|
||||||
```
|
|
||||||
|
|
||||||
### `hash`
|
|
||||||
|
|
||||||
Hashes input data using a specified algorithm.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
trix hash [algorithm] [flags]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Arguments:**
|
|
||||||
|
|
||||||
* `algorithm`: The hash algorithm to use (e.g., `sha256`, `md5`, `lthn`).
|
|
||||||
|
|
||||||
**Flags:**
|
|
||||||
|
|
||||||
* `-i, --input string`: Input file path. If not specified, reads from stdin.
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
echo "hello" | trix hash sha256
|
|
||||||
```
|
|
||||||
|
|
||||||
### Sigil Commands
|
|
||||||
|
|
||||||
You can apply individual sigils directly to data.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
trix [sigil_name] [flags]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Available Sigils:**
|
|
||||||
|
|
||||||
* `reverse`
|
|
||||||
* `hex`
|
|
||||||
* `base64`
|
|
||||||
* `gzip`
|
|
||||||
* `json`, `json-indent`
|
|
||||||
* `md4`, `md5`, `sha1`, `sha224`, `sha256`, `sha384`, `sha512`
|
|
||||||
* `ripemd160`
|
|
||||||
* `sha3-224`, `sha3-256`, `sha3-384`, `sha3-512`
|
|
||||||
* `sha512-224`, `sha512-256`
|
|
||||||
* `blake2s-256`, `blake2b-256`, `blake2b-384`, `blake2b-512`
|
|
||||||
|
|
||||||
**Flags:**
|
|
||||||
|
|
||||||
* `-i, --input string`: Input file or string. Use `-` for stdin.
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Base64 encode a string
|
|
||||||
trix base64 -i "hello world"
|
|
||||||
|
|
||||||
# Gzip a file
|
|
||||||
trix gzip -i myfile.txt > myfile.txt.gz
|
|
||||||
```
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
# Hashing
|
|
||||||
|
|
||||||
This example demonstrates how to use the `crypt` service to hash a payload using various algorithms.
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func demoHashing() {
|
|
||||||
fmt.Println("--- Hashing Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
payload := "Enchantrix"
|
|
||||||
|
|
||||||
hashTypes := []crypt.HashType{
|
|
||||||
crypt.LTHN,
|
|
||||||
crypt.MD5,
|
|
||||||
crypt.SHA1,
|
|
||||||
crypt.SHA256,
|
|
||||||
crypt.SHA512,
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Payload to hash: \"%s\"\n", payload)
|
|
||||||
for _, hashType := range hashTypes {
|
|
||||||
hash := cryptService.Hash(hashType, payload)
|
|
||||||
fmt.Printf(" - %-6s: %s\n", hashType, hash)
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
# Welcome to Enchantrix
|
|
||||||
|
|
||||||
Enchantrix is a Go-based crypto library and miner application. This documentation provides information on how to use the various features of the Enchantrix library.
|
|
||||||
|
|
||||||
## Trix File Format
|
|
||||||
|
|
||||||
The `.trix` file format is a generic and flexible binary container for storing an arbitrary data payload alongside structured metadata. For more information, see the [Trix File Format](./trix_format.md) page.
|
|
||||||
|
|
||||||
## CLI Reference
|
|
||||||
|
|
||||||
Enchantrix provides a command-line tool for encoding, decoding, and hashing data. See the [CLI Reference](./cli.md) for detailed usage instructions.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
The following pages provide examples of how to use the Enchantrix library:
|
|
||||||
|
|
||||||
* [Trix & Sigil Chaining](./trix_and_sigils.md)
|
|
||||||
* [Hashing](./hashing.md)
|
|
||||||
* [Checksums](./checksums.md)
|
|
||||||
* [RSA](./rsa.md)
|
|
||||||
* [PGP](./pgp.md)
|
|
||||||
* [Standalone Sigils](./standalone_sigils.md)
|
|
||||||
76
docs/pgp.md
76
docs/pgp.md
|
|
@ -1,76 +0,0 @@
|
||||||
# PGP
|
|
||||||
|
|
||||||
This example demonstrates how to use the `crypt` service to perform PGP operations, including key generation, encryption, decryption, signing, and verification.
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func demoPGP() {
|
|
||||||
fmt.Println("--- PGP Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// 1. Generate PGP Key Pair
|
|
||||||
fmt.Println("Generating PGP key pair...")
|
|
||||||
publicKey, privateKey, err := cryptService.GeneratePGPKeyPair("Alice", "alice@example.com", "Demo Key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("PGP Key pair generated successfully.")
|
|
||||||
|
|
||||||
// 2. Asymmetric Encryption (Public Key Encryption)
|
|
||||||
message := []byte("This is a secret message for PGP.")
|
|
||||||
fmt.Printf("\nOriginal message: %s\n", message)
|
|
||||||
|
|
||||||
encrypted, err := cryptService.EncryptPGP(publicKey, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Message encrypted.")
|
|
||||||
|
|
||||||
// 3. Decrypt with Private Key
|
|
||||||
decrypted, err := cryptService.DecryptPGP(privateKey, encrypted)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to decrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Decrypted message: %s\n", decrypted)
|
|
||||||
|
|
||||||
if string(message) == string(decrypted) {
|
|
||||||
fmt.Println("Success! PGP decrypted message matches original.")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Failure! PGP decrypted message does not match.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Signing and Verification
|
|
||||||
fmt.Println("\n--- PGP Signing Demo ---")
|
|
||||||
signature, err := cryptService.SignPGP(privateKey, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to sign message: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Message signed.")
|
|
||||||
|
|
||||||
err = cryptService.VerifyPGP(publicKey, message, signature)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to verify signature: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Success! Signature verified.")
|
|
||||||
|
|
||||||
// 5. Symmetric Encryption (Passphrase)
|
|
||||||
fmt.Println("\n--- PGP Symmetric Encryption Demo ---")
|
|
||||||
passphrase := []byte("super-secure-passphrase")
|
|
||||||
symEncrypted, err := cryptService.SymmetricallyEncryptPGP(passphrase, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to symmetrically encrypt: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Message symmetrically encrypted.")
|
|
||||||
// Note: Decryption of symmetrically encrypted PGP messages requires a compatible reader
|
|
||||||
// or usage of the underlying library's features, often handled automatically
|
|
||||||
// if the decryptor prompts for a passphrase.
|
|
||||||
}
|
|
||||||
```
|
|
||||||
52
docs/rsa.md
52
docs/rsa.md
|
|
@ -1,52 +0,0 @@
|
||||||
# RSA
|
|
||||||
|
|
||||||
This example demonstrates how to use the `crypt` service to generate an RSA key pair, encrypt a message, and then decrypt it.
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func demoRSA() {
|
|
||||||
fmt.Println("--- RSA Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// 1. Generate RSA key pair
|
|
||||||
fmt.Println("Generating 2048-bit RSA key pair...")
|
|
||||||
publicKey, privateKey, err := cryptService.GenerateRSAKeyPair(2048)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate RSA key pair: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Key pair generated successfully.")
|
|
||||||
|
|
||||||
// 2. Encrypt a message
|
|
||||||
message := []byte("This is a secret message for RSA.")
|
|
||||||
fmt.Printf("\nOriginal message: %s\n", message)
|
|
||||||
ciphertext, err := cryptService.EncryptRSA(publicKey, message, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encrypt with RSA: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Encrypted ciphertext (base64): %s\n", base64.StdEncoding.EncodeToString(ciphertext))
|
|
||||||
|
|
||||||
// 3. Decrypt the message
|
|
||||||
decrypted, err := cryptService.DecryptRSA(privateKey, ciphertext, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to decrypt with RSA: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Decrypted message: %s\n", decrypted)
|
|
||||||
|
|
||||||
// 4. Verify
|
|
||||||
if string(message) == string(decrypted) {
|
|
||||||
fmt.Println("\nSuccess! RSA decrypted message matches the original.")
|
|
||||||
} else {
|
|
||||||
fmt.Println("\nFailure! RSA decrypted message does not match the original.")
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
# Standalone Sigils
|
|
||||||
|
|
||||||
This example demonstrates how to use sigils independently to transform data.
|
|
||||||
|
|
||||||
## Available Sigils
|
|
||||||
|
|
||||||
The `enchantrix` package provides a wide variety of sigils for data transformation and hashing.
|
|
||||||
|
|
||||||
| Category | Sigils |
|
|
||||||
| :--- | :--- |
|
|
||||||
| **Encoding** | `hex`, `base64`, `reverse` |
|
|
||||||
| **Compression** | `gzip` |
|
|
||||||
| **Formatting** | `json`, `json-indent` |
|
|
||||||
| **Standard Hashes** | `md4`, `md5`, `sha1`, `sha224`, `sha256`, `sha384`, `sha512` |
|
|
||||||
| **Extended Hashes** | `ripemd160`, `sha3-224`, `sha3-256`, `sha3-384`, `sha3-512`, `sha512-224`, `sha512-256` |
|
|
||||||
| **Blake Hashes** | `blake2s-256`, `blake2b-256`, `blake2b-384`, `blake2b-512` |
|
|
||||||
|
|
||||||
## Usage Example
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/enchantrix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func demoSigils() {
|
|
||||||
fmt.Println("--- Standalone Sigil Demo ---")
|
|
||||||
data := []byte(`{"message": "hello world"}`)
|
|
||||||
fmt.Printf("Original data: %s\n", data)
|
|
||||||
|
|
||||||
// A chain of sigils to apply
|
|
||||||
sigils := []string{"gzip", "base64"}
|
|
||||||
fmt.Printf("Applying sigil chain: %v\n", sigils)
|
|
||||||
|
|
||||||
var transformedData = data
|
|
||||||
for _, name := range sigils {
|
|
||||||
s, err := enchantrix.NewSigil(name)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to create sigil %s: %v", name, err)
|
|
||||||
}
|
|
||||||
transformedData, err = s.In(transformedData)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to apply sigil %s 'In': %v", name, err)
|
|
||||||
}
|
|
||||||
fmt.Printf(" -> After '%s': %s\n", name, transformedData)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("\nReversing sigil chain...")
|
|
||||||
// Reverse the transformations
|
|
||||||
for i := len(sigils) - 1; i >= 0; i-- {
|
|
||||||
name := sigils[i]
|
|
||||||
s, err := enchantrix.NewSigil(name)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to create sigil %s: %v", name, err)
|
|
||||||
}
|
|
||||||
transformedData, err = s.Out(transformedData)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to apply sigil %s 'Out': %v", name, err)
|
|
||||||
}
|
|
||||||
fmt.Printf(" -> After '%s' Out: %s\n", name, transformedData)
|
|
||||||
}
|
|
||||||
|
|
||||||
if string(data) == string(transformedData) {
|
|
||||||
fmt.Println("Success! Data returned to original state.")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Failure! Data did not return to original state.")
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
@ -1,124 +0,0 @@
|
||||||
# Trix & Sigil Chaining
|
|
||||||
|
|
||||||
This example demonstrates how to use the Trix container with a chain of sigils to obfuscate and then encrypt a payload.
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt/std/chachapoly"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/trix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func demoTrix() {
|
|
||||||
fmt.Println("--- Trix & Sigil Chaining Demo ---")
|
|
||||||
|
|
||||||
// 1. Original plaintext (JSON data) and encryption key
|
|
||||||
type Message struct {
|
|
||||||
Author string `json:"author"`
|
|
||||||
Time int64 `json:"time"`
|
|
||||||
Body string `json:"body"`
|
|
||||||
}
|
|
||||||
originalMessage := Message{Author: "Jules", Time: time.Now().Unix(), Body: "This is a super secret message!"}
|
|
||||||
plaintext, err := json.Marshal(originalMessage)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to marshal JSON: %v", err)
|
|
||||||
}
|
|
||||||
key := make([]byte, 32) // In a real application, use a secure key
|
|
||||||
for i := range key {
|
|
||||||
key[i] = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Original Payload (JSON):\n%s\n\n", plaintext)
|
|
||||||
|
|
||||||
// 2. Create a Trix container with the plaintext and attach a chain of sigils
|
|
||||||
sigilChain := []string{"json-indent", "gzip", "base64", "reverse"}
|
|
||||||
trixContainer := &trix.Trix{
|
|
||||||
Header: map[string]interface{}{},
|
|
||||||
Payload: plaintext,
|
|
||||||
InSigils: sigilChain,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Pack the Trix container to apply the sigil transformations
|
|
||||||
fmt.Println("Packing payload with sigils:", sigilChain)
|
|
||||||
if err := trixContainer.Pack(); err != nil {
|
|
||||||
log.Fatalf("Failed to pack trix container: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Packed (obfuscated) payload is now non-human-readable bytes.\n\n")
|
|
||||||
|
|
||||||
// 4. Encrypt the packed payload
|
|
||||||
ciphertext, err := chachapoly.Encrypt(trixContainer.Payload, key)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encrypt: %v", err)
|
|
||||||
}
|
|
||||||
trixContainer.Payload = ciphertext // Update the payload with the ciphertext
|
|
||||||
|
|
||||||
// 5. Add encryption metadata and checksum to the header
|
|
||||||
nonce := ciphertext[:24]
|
|
||||||
trixContainer.Header = map[string]interface{}{
|
|
||||||
"content_type": "application/json",
|
|
||||||
"encryption_algorithm": "chacha20poly1305",
|
|
||||||
"nonce": base64.StdEncoding.EncodeToString(nonce),
|
|
||||||
"created_at": time.Now().UTC().Format(time.RFC3339),
|
|
||||||
}
|
|
||||||
trixContainer.ChecksumAlgo = crypt.SHA512
|
|
||||||
fmt.Printf("Checksum will be calculated with %s and added to the header.\n", trixContainer.ChecksumAlgo)
|
|
||||||
|
|
||||||
// 6. Encode the .trix container into its binary format
|
|
||||||
magicNumber := "MyT1"
|
|
||||||
encodedTrix, err := trix.Encode(trixContainer, magicNumber, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encode .trix container: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Successfully created .trix container.")
|
|
||||||
|
|
||||||
// --- DECODING ---
|
|
||||||
fmt.Println("--- DECODING ---")
|
|
||||||
|
|
||||||
// 7. Decode the .trix container
|
|
||||||
decodedTrix, err := trix.Decode(encodedTrix, magicNumber, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to decode .trix container: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Successfully decoded .trix container. Checksum verified.")
|
|
||||||
fmt.Printf("Decoded Header: %+v\n", decodedTrix.Header)
|
|
||||||
|
|
||||||
// 8. Decrypt the payload
|
|
||||||
decryptedPayload, err := chachapoly.Decrypt(decodedTrix.Payload, key)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to decrypt: %v", err)
|
|
||||||
}
|
|
||||||
decodedTrix.Payload = decryptedPayload
|
|
||||||
fmt.Println("Payload decrypted.")
|
|
||||||
|
|
||||||
// 9. Unpack the Trix container to reverse the sigil transformations
|
|
||||||
decodedTrix.InSigils = trixContainer.InSigils // Re-attach sigils for unpacking
|
|
||||||
fmt.Println("Unpacking payload by reversing sigils:", decodedTrix.InSigils)
|
|
||||||
if err := decodedTrix.Unpack(); err != nil {
|
|
||||||
log.Fatalf("Failed to unpack trix container: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Unpacked (original) payload:\n%s\n", decodedTrix.Payload)
|
|
||||||
|
|
||||||
// 10. Verify the result
|
|
||||||
// To properly verify, we need to compact the indented JSON before comparing
|
|
||||||
var compactedPayload bytes.Buffer
|
|
||||||
if err := json.Compact(&compactedPayload, decodedTrix.Payload); err != nil {
|
|
||||||
log.Fatalf("Failed to compact final payload for verification: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes.Equal(plaintext, compactedPayload.Bytes()) {
|
|
||||||
fmt.Println("\nSuccess! The message was decrypted and unpacked correctly.")
|
|
||||||
} else {
|
|
||||||
fmt.Println("\nFailure! The final payload does not match the original.")
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
# .trix File Format v2.0
|
|
||||||
|
|
||||||
The `.trix` file format is a generic and flexible binary container for storing an arbitrary data payload alongside structured metadata.
|
|
||||||
|
|
||||||
## Structure
|
|
||||||
|
|
||||||
The file is structured as follows:
|
|
||||||
|
|
||||||
| Field | Size (bytes) | Description |
|
|
||||||
|----------------|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
||||||
| **Magic Number** | 4 | A constant value, `TRIX`, to identify the file as a `.trix` file. |
|
|
||||||
| **Version** | 1 | The version of the `.trix` file format (currently `2`). |
|
|
||||||
| **Header Length**| 4 | A 32-bit unsigned integer specifying the length of the JSON Header in bytes. This allows for flexible and extensible metadata. |
|
|
||||||
| **JSON Header** | `Header Length` | A UTF-8 encoded JSON object containing metadata about the payload. Common keys include `content_type`, `encryption_algorithm`, `nonce`, `tag`, and `created_at`. |
|
|
||||||
| **Payload** | variable | The raw binary data. This can be plaintext, ciphertext, or any other data. The interpretation of this data is guided by the metadata in the JSON Header. |
|
|
||||||
|
|
||||||
## Example JSON Header
|
|
||||||
|
|
||||||
Here is an example of what the JSON header might look like for a file encrypted with ChaCha20-Poly1305:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"content_type": "application/octet-stream",
|
|
||||||
"encryption_algorithm": "chacha20poly1305",
|
|
||||||
"nonce": "AAECAwQFBgcICQoLDA0ODxAREhMUFRY=",
|
|
||||||
"created_at": "2025-10-30T12:00:00Z"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This decoupled design ensures that the `.trix` container is not tied to any specific encryption scheme, allowing for greater flexibility and future-proofing.
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
// Example: Checksum algorithms
|
|
||||||
//
|
|
||||||
// This example demonstrates Luhn and Fletcher checksum algorithms
|
|
||||||
// for data integrity verification.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/checksums/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- Checksum Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// Luhn
|
|
||||||
luhnPayloadGood := "49927398716"
|
|
||||||
luhnPayloadBad := "49927398717"
|
|
||||||
fmt.Printf("Luhn Checksum:\n")
|
|
||||||
fmt.Printf(" - Payload '%s' is valid: %v\n", luhnPayloadGood, cryptService.Luhn(luhnPayloadGood))
|
|
||||||
fmt.Printf(" - Payload '%s' is valid: %v\n", luhnPayloadBad, cryptService.Luhn(luhnPayloadBad))
|
|
||||||
|
|
||||||
// Fletcher
|
|
||||||
fletcherPayload := "abcde"
|
|
||||||
fmt.Printf("\nFletcher Checksums (Payload: \"%s\"):\n", fletcherPayload)
|
|
||||||
fmt.Printf(" - Fletcher16: %d\n", cryptService.Fletcher16(fletcherPayload))
|
|
||||||
fmt.Printf(" - Fletcher32: %d\n", cryptService.Fletcher32(fletcherPayload))
|
|
||||||
fmt.Printf(" - Fletcher64: %d\n", cryptService.Fletcher64(fletcherPayload))
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- Test Coverage Demo ---")
|
|
||||||
fmt.Println("")
|
|
||||||
fmt.Println("This example demonstrates how to generate and interpret a test coverage report.")
|
|
||||||
fmt.Println("")
|
|
||||||
fmt.Println("1. Generate a coverage profile:")
|
|
||||||
fmt.Println(" go test ./... -coverprofile=coverage.out")
|
|
||||||
fmt.Println("")
|
|
||||||
fmt.Println("2. View the coverage report in your browser:")
|
|
||||||
fmt.Println(" go tool cover -html=coverage.out")
|
|
||||||
fmt.Println("")
|
|
||||||
fmt.Println("3. View the coverage report in your terminal:")
|
|
||||||
fmt.Println(" go tool cover -func=coverage.out")
|
|
||||||
fmt.Println("")
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
package examples_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os/exec"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestExample_Checksums(t *testing.T) {
|
|
||||||
cmd := exec.Command("go", "run", ".")
|
|
||||||
cmd.Dir = "./checksums"
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
assert.NoError(t, err, string(out))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExample_Hash(t *testing.T) {
|
|
||||||
cmd := exec.Command("go", "run", ".")
|
|
||||||
cmd.Dir = "./hash"
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
assert.NoError(t, err, string(out))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExample_PGPEncryptDecrypt(t *testing.T) {
|
|
||||||
cmd := exec.Command("go", "run", ".")
|
|
||||||
cmd.Dir = "./pgp_encrypt_decrypt"
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
assert.NoError(t, err, string(out))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExample_PGPGenerateKeys(t *testing.T) {
|
|
||||||
cmd := exec.Command("go", "run", ".")
|
|
||||||
cmd.Dir = "./pgp_generate_keys"
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
assert.NoError(t, err, string(out))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExample_PGPSignVerify(t *testing.T) {
|
|
||||||
cmd := exec.Command("go", "run", ".")
|
|
||||||
cmd.Dir = "./pgp_sign_verify"
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
assert.NoError(t, err, string(out))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExample_PGPSymmetricEncrypt(t *testing.T) {
|
|
||||||
cmd := exec.Command("go", "run", ".")
|
|
||||||
cmd.Dir = "./pgp_symmetric_encrypt"
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
assert.NoError(t, err, string(out))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExample_RSA(t *testing.T) {
|
|
||||||
cmd := exec.Command("go", "run", ".")
|
|
||||||
cmd.Dir = "./rsa"
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
assert.NoError(t, err, string(out))
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
// Example: Hashing with multiple algorithms
|
|
||||||
//
|
|
||||||
// This example demonstrates how to use the crypt service to compute hashes
|
|
||||||
// using various algorithms including the custom LTHN quasi-salted hash.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/hash/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- Hashing Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
payload := "Enchantrix"
|
|
||||||
|
|
||||||
hashTypes := []crypt.HashType{
|
|
||||||
crypt.LTHN,
|
|
||||||
crypt.MD5,
|
|
||||||
crypt.SHA1,
|
|
||||||
crypt.SHA256,
|
|
||||||
crypt.SHA512,
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Payload to hash: \"%s\"\n", payload)
|
|
||||||
for _, hashType := range hashTypes {
|
|
||||||
hash := cryptService.Hash(hashType, payload)
|
|
||||||
fmt.Printf(" - %-6s: %s\n", hashType, hash)
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
// Example: PGP encryption and decryption
|
|
||||||
//
|
|
||||||
// This example demonstrates OpenPGP key generation, asymmetric encryption,
|
|
||||||
// and decryption. PGP provides end-to-end encryption with ASCII-armored
|
|
||||||
// output suitable for email and text-based transport.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/pgp_encrypt_decrypt/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- PGP Encryption & Decryption Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// 1. Generate PGP key pair
|
|
||||||
fmt.Println("Generating PGP key pair...")
|
|
||||||
publicKey, privateKey, err := cryptService.GeneratePGPKeyPair("test", "test@example.com", "test key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Key pair generated successfully.")
|
|
||||||
|
|
||||||
// 2. Encrypt a message
|
|
||||||
message := []byte("This is a secret message for PGP.")
|
|
||||||
fmt.Printf("\nOriginal message: %s\n", message)
|
|
||||||
ciphertext, err := cryptService.EncryptPGP(publicKey, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Encrypted ciphertext (armored):\n%s\n", ciphertext)
|
|
||||||
|
|
||||||
// 3. Decrypt the message
|
|
||||||
decrypted, err := cryptService.DecryptPGP(privateKey, ciphertext)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to decrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Decrypted message: %s\n", decrypted)
|
|
||||||
|
|
||||||
// 4. Verify
|
|
||||||
if string(message) == string(decrypted) {
|
|
||||||
fmt.Println("\nSuccess! PGP decrypted message matches the original.")
|
|
||||||
} else {
|
|
||||||
fmt.Println("\nFailure! PGP decrypted message does not match the original.")
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
// Example: PGP key pair generation
|
|
||||||
//
|
|
||||||
// This example demonstrates generating an OpenPGP key pair with
|
|
||||||
// name, email, and comment metadata. The output is ASCII-armored
|
|
||||||
// for easy storage and distribution.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/pgp_generate_keys/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- PGP Key Generation Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// 1. Generate PGP key pair
|
|
||||||
fmt.Println("Generating PGP key pair...")
|
|
||||||
publicKey, privateKey, err := cryptService.GeneratePGPKeyPair("test", "test@example.com", "test key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Key pair generated successfully.")
|
|
||||||
fmt.Printf("\nPublic Key:\n%s\n", publicKey)
|
|
||||||
fmt.Printf("\nPrivate Key:\n%s\n", privateKey)
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
// Example: PGP digital signatures
|
|
||||||
//
|
|
||||||
// This example demonstrates creating and verifying PGP digital signatures.
|
|
||||||
// Signatures provide authenticity and integrity verification without
|
|
||||||
// encrypting the message content.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/pgp_sign_verify/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- PGP Signing & Verification Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// 1. Generate PGP key pair
|
|
||||||
fmt.Println("Generating PGP key pair...")
|
|
||||||
publicKey, privateKey, err := cryptService.GeneratePGPKeyPair("test", "test@example.com", "test key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Key pair generated successfully.")
|
|
||||||
|
|
||||||
// 2. Sign a message
|
|
||||||
message := []byte("This is a message to be signed.")
|
|
||||||
fmt.Printf("\nOriginal message: %s\n", message)
|
|
||||||
signature, err := cryptService.SignPGP(privateKey, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to sign with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Signature (armored):\n%s\n", signature)
|
|
||||||
|
|
||||||
// 3. Verify the signature
|
|
||||||
err = cryptService.VerifyPGP(publicKey, message, signature)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to verify signature: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Signature verified successfully!")
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
// Example: PGP symmetric (passphrase-based) encryption
|
|
||||||
//
|
|
||||||
// This example demonstrates symmetric encryption using a passphrase
|
|
||||||
// instead of public/private key pairs. Useful when you need to share
|
|
||||||
// encrypted data with someone using a pre-shared password.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/pgp_symmetric_encrypt/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- PGP Symmetric Encryption Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// 1. Encrypt a message with a passphrase
|
|
||||||
message := []byte("This is a secret message for symmetric PGP encryption.")
|
|
||||||
passphrase := []byte("my-secret-passphrase")
|
|
||||||
fmt.Printf("\nOriginal message: %s\n", message)
|
|
||||||
ciphertext, err := cryptService.SymmetricallyEncryptPGP(passphrase, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Encrypted ciphertext (armored):\n%s\n", ciphertext)
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
// Example: RSA encryption and decryption
|
|
||||||
//
|
|
||||||
// This example demonstrates RSA key generation, encryption, and decryption
|
|
||||||
// using the crypt service. RSA is suitable for encrypting small amounts of
|
|
||||||
// data or for key exchange protocols.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/rsa/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- RSA Demo ---")
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
|
|
||||||
// 1. Generate RSA key pair
|
|
||||||
fmt.Println("Generating 2048-bit RSA key pair...")
|
|
||||||
publicKey, privateKey, err := cryptService.GenerateRSAKeyPair(2048)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate RSA key pair: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Key pair generated successfully.")
|
|
||||||
|
|
||||||
// 2. Encrypt a message
|
|
||||||
message := []byte("This is a secret message for RSA.")
|
|
||||||
fmt.Printf("\nOriginal message: %s\n", message)
|
|
||||||
ciphertext, err := cryptService.EncryptRSA(publicKey, message, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encrypt with RSA: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Encrypted ciphertext (base64): %s\n", base64.StdEncoding.EncodeToString(ciphertext))
|
|
||||||
|
|
||||||
// 3. Decrypt the message
|
|
||||||
decrypted, err := cryptService.DecryptRSA(privateKey, ciphertext, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to decrypt with RSA: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Decrypted message: %s\n", decrypted)
|
|
||||||
|
|
||||||
// 4. Verify
|
|
||||||
if string(message) == string(decrypted) {
|
|
||||||
fmt.Println("\nSuccess! RSA decrypted message matches the original.")
|
|
||||||
} else {
|
|
||||||
fmt.Println("\nFailure! RSA decrypted message does not match the original.")
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
// Example: Sigil transformation framework
|
|
||||||
//
|
|
||||||
// This example demonstrates the Sigil transformation framework, showing
|
|
||||||
// how to create transformation pipelines for encoding, compression, and
|
|
||||||
// hashing. Sigils can be chained together and reversed.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/sigils/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/enchantrix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- Sigil Transformation Demo ---")
|
|
||||||
|
|
||||||
// Original data
|
|
||||||
data := []byte("Hello, Enchantrix! This is a demonstration of the Sigil framework.")
|
|
||||||
fmt.Printf("Original data (%d bytes): %s\n\n", len(data), data)
|
|
||||||
|
|
||||||
// 1. Single sigil transformation
|
|
||||||
fmt.Println("1. Single Sigil (hex encoding):")
|
|
||||||
hexSigil, _ := enchantrix.NewSigil("hex")
|
|
||||||
hexEncoded, _ := hexSigil.In(data)
|
|
||||||
fmt.Printf(" Hex encoded: %s\n", hexEncoded)
|
|
||||||
hexDecoded, _ := hexSigil.Out(hexEncoded)
|
|
||||||
fmt.Printf(" Hex decoded: %s\n\n", hexDecoded)
|
|
||||||
|
|
||||||
// 2. Chained sigils using Transmute
|
|
||||||
fmt.Println("2. Chained Sigils (gzip -> base64):")
|
|
||||||
gzipSigil, _ := enchantrix.NewSigil("gzip")
|
|
||||||
base64Sigil, _ := enchantrix.NewSigil("base64")
|
|
||||||
|
|
||||||
// Apply chain: data -> gzip -> base64
|
|
||||||
compressed, _ := gzipSigil.In(data)
|
|
||||||
fmt.Printf(" After gzip (%d bytes)\n", len(compressed))
|
|
||||||
|
|
||||||
result, _ := enchantrix.Transmute(data, []enchantrix.Sigil{gzipSigil, base64Sigil})
|
|
||||||
fmt.Printf(" After gzip+base64 (%d bytes): %s...\n\n", len(result), result[:50])
|
|
||||||
|
|
||||||
// 3. Reverse the chain
|
|
||||||
fmt.Println("3. Reversing the Chain:")
|
|
||||||
// Reverse order: base64.Out -> gzip.Out
|
|
||||||
step1, _ := base64Sigil.Out(result)
|
|
||||||
original, _ := gzipSigil.Out(step1)
|
|
||||||
fmt.Printf(" Recovered: %s\n\n", original)
|
|
||||||
|
|
||||||
// 4. Hash sigils (irreversible)
|
|
||||||
fmt.Println("4. Hash Sigils (irreversible):")
|
|
||||||
sha256Sigil, _ := enchantrix.NewSigil("sha256")
|
|
||||||
hash, _ := sha256Sigil.In(data)
|
|
||||||
fmt.Printf(" SHA-256 hash (%d bytes): %x\n", len(hash), hash)
|
|
||||||
|
|
||||||
// Hash.Out is a no-op (returns input unchanged)
|
|
||||||
passthrough, _ := sha256Sigil.Out(hash)
|
|
||||||
fmt.Printf(" Hash.Out (passthrough): %x\n\n", passthrough)
|
|
||||||
|
|
||||||
// 5. Symmetric sigil (reverse)
|
|
||||||
fmt.Println("5. Symmetric Sigil (byte reversal):")
|
|
||||||
reverseSigil, _ := enchantrix.NewSigil("reverse")
|
|
||||||
reversed, _ := reverseSigil.In([]byte("Hello"))
|
|
||||||
fmt.Printf(" 'Hello' reversed: %s\n", reversed)
|
|
||||||
// In and Out do the same thing for symmetric sigils
|
|
||||||
unreversed, _ := reverseSigil.Out(reversed)
|
|
||||||
fmt.Printf(" Reversed again: %s\n\n", unreversed)
|
|
||||||
|
|
||||||
// 6. Available sigils
|
|
||||||
fmt.Println("6. Available Sigils:")
|
|
||||||
sigils := []string{
|
|
||||||
"hex", "base64", "gzip", "reverse", "json", "json-indent",
|
|
||||||
"md5", "sha1", "sha256", "sha512", "blake2b-256",
|
|
||||||
}
|
|
||||||
for _, name := range sigils {
|
|
||||||
sigil, err := enchantrix.NewSigil(name)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf(" - %s: ERROR\n", name)
|
|
||||||
} else {
|
|
||||||
_ = sigil // sigil is valid
|
|
||||||
fmt.Printf(" - %s: OK\n", name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,122 +0,0 @@
|
||||||
// Example: .trix container format
|
|
||||||
//
|
|
||||||
// This example demonstrates the .trix binary container format for packaging
|
|
||||||
// data with metadata and optional transformations. The format supports
|
|
||||||
// custom magic numbers, JSON headers, and sigil-based transformation pipelines.
|
|
||||||
//
|
|
||||||
// Run with: go run examples/trix_container/main.go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/trix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("--- .trix Container Format Demo ---")
|
|
||||||
|
|
||||||
// 1. Create a simple container
|
|
||||||
fmt.Println("\n1. Simple Container:")
|
|
||||||
simple := &trix.Trix{
|
|
||||||
Header: map[string]interface{}{
|
|
||||||
"content_type": "text/plain",
|
|
||||||
"created_at": time.Now().UTC().Format(time.RFC3339),
|
|
||||||
"author": "Enchantrix Demo",
|
|
||||||
},
|
|
||||||
Payload: []byte("Hello, this is the payload data!"),
|
|
||||||
}
|
|
||||||
|
|
||||||
encoded, err := trix.Encode(simple, "DEMO", nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encode: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf(" Encoded size: %d bytes\n", len(encoded))
|
|
||||||
fmt.Printf(" Magic number: %s\n", encoded[:4])
|
|
||||||
fmt.Printf(" Version: %d\n", encoded[4])
|
|
||||||
|
|
||||||
// Decode it back
|
|
||||||
decoded, err := trix.Decode(encoded, "DEMO", nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to decode: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf(" Decoded payload: %s\n", decoded.Payload)
|
|
||||||
fmt.Printf(" Header content_type: %s\n", decoded.Header["content_type"])
|
|
||||||
|
|
||||||
// 2. Container with checksum verification
|
|
||||||
fmt.Println("\n2. Container with Checksum:")
|
|
||||||
withChecksum := &trix.Trix{
|
|
||||||
Header: map[string]interface{}{
|
|
||||||
"content_type": "application/octet-stream",
|
|
||||||
},
|
|
||||||
Payload: []byte("Important data that needs integrity verification"),
|
|
||||||
ChecksumAlgo: crypt.SHA256,
|
|
||||||
}
|
|
||||||
|
|
||||||
encodedWithChecksum, _ := trix.Encode(withChecksum, "CHKS", nil)
|
|
||||||
fmt.Printf(" Encoded size: %d bytes\n", len(encodedWithChecksum))
|
|
||||||
|
|
||||||
// Decode and verify checksum automatically
|
|
||||||
decodedWithChecksum, err := trix.Decode(encodedWithChecksum, "CHKS", nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Checksum verification failed: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf(" Checksum verified! Algorithm: %s\n", decodedWithChecksum.Header["checksum_algo"])
|
|
||||||
fmt.Printf(" Checksum value: %s...\n", decodedWithChecksum.Header["checksum"].(string)[:32])
|
|
||||||
|
|
||||||
// 3. Container with sigil transformations
|
|
||||||
fmt.Println("\n3. Container with Sigil Transformations:")
|
|
||||||
withSigils := &trix.Trix{
|
|
||||||
Header: map[string]interface{}{
|
|
||||||
"content_type": "text/plain",
|
|
||||||
"transformed": true,
|
|
||||||
},
|
|
||||||
Payload: []byte("This data will be compressed and encoded!"),
|
|
||||||
InSigils: []string{"gzip", "base64"},
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf(" Original payload size: %d bytes\n", len(withSigils.Payload))
|
|
||||||
|
|
||||||
// Pack applies InSigils
|
|
||||||
if err := withSigils.Pack(); err != nil {
|
|
||||||
log.Fatalf("Pack failed: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf(" After Pack (gzip+base64): %d bytes\n", len(withSigils.Payload))
|
|
||||||
|
|
||||||
encodedWithSigils, _ := trix.Encode(withSigils, "TRNS", nil)
|
|
||||||
fmt.Printf(" Final encoded size: %d bytes\n", len(encodedWithSigils))
|
|
||||||
|
|
||||||
// Decode and unpack
|
|
||||||
decodedWithSigils, _ := trix.Decode(encodedWithSigils, "TRNS", nil)
|
|
||||||
decodedWithSigils.OutSigils = []string{"gzip", "base64"} // Must match InSigils
|
|
||||||
|
|
||||||
if err := decodedWithSigils.Unpack(); err != nil {
|
|
||||||
log.Fatalf("Unpack failed: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf(" Unpacked payload: %s\n", decodedWithSigils.Payload)
|
|
||||||
|
|
||||||
// 4. Custom magic numbers for different applications
|
|
||||||
fmt.Println("\n4. Custom Magic Numbers:")
|
|
||||||
apps := []struct {
|
|
||||||
magic string
|
|
||||||
desc string
|
|
||||||
}{
|
|
||||||
{"CONF", "Configuration files"},
|
|
||||||
{"LOGS", "Log archives"},
|
|
||||||
{"KEYS", "Key storage"},
|
|
||||||
{"MSGS", "Encrypted messages"},
|
|
||||||
}
|
|
||||||
for _, app := range apps {
|
|
||||||
container := &trix.Trix{
|
|
||||||
Header: map[string]interface{}{"app": app.desc},
|
|
||||||
Payload: []byte("sample"),
|
|
||||||
}
|
|
||||||
data, _ := trix.Encode(container, app.magic, nil)
|
|
||||||
fmt.Printf(" %s: %s (%d bytes)\n", app.magic, app.desc, len(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("\nDone!")
|
|
||||||
}
|
|
||||||
20
go.mod
20
go.mod
|
|
@ -1,20 +0,0 @@
|
||||||
module github.com/Snider/Enchantrix
|
|
||||||
|
|
||||||
go 1.25
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/ProtonMail/go-crypto v1.3.0
|
|
||||||
github.com/spf13/cobra v1.10.1
|
|
||||||
github.com/stretchr/testify v1.11.1
|
|
||||||
golang.org/x/crypto v0.43.0
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cloudflare/circl v1.6.0 // indirect
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
github.com/spf13/pflag v1.0.9 // indirect
|
|
||||||
golang.org/x/sys v0.37.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
)
|
|
||||||
26
go.sum
26
go.sum
|
|
@ -1,26 +0,0 @@
|
||||||
github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=
|
|
||||||
github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
|
|
||||||
github.com/cloudflare/circl v1.6.0 h1:cr5JKic4HI+LkINy2lg3W2jF8sHCVTBncJr5gIIq7qk=
|
|
||||||
github.com/cloudflare/circl v1.6.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
|
||||||
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
|
|
||||||
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
|
|
||||||
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
|
|
||||||
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
|
||||||
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
|
|
||||||
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
|
|
||||||
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
|
|
||||||
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
3
go.work
3
go.work
|
|
@ -1,3 +0,0 @@
|
||||||
go 1.25
|
|
||||||
|
|
||||||
use .
|
|
||||||
12
go.work.sum
12
go.work.sum
|
|
@ -1,12 +0,0 @@
|
||||||
github.com/bwesterb/go-ristretto v1.2.3 h1:1w53tCkGhCQ5djbat3+MH0BAQ5Kfgbt56UZQ/JMzngw=
|
|
||||||
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
|
||||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
|
||||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
|
||||||
golang.org/x/net v0.45.0 h1:RLBg5JKixCy82FtLJpeNlVM0nrSqpCRYzVU1n8kj0tM=
|
|
||||||
golang.org/x/net v0.45.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
|
|
||||||
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
|
|
||||||
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
|
|
||||||
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
|
|
||||||
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
|
|
||||||
526
hashing/index.html
Normal file
526
hashing/index.html
Normal file
|
|
@ -0,0 +1,526 @@
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en" class="no-js">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="prev" href="../trix_and_sigils/">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="next" href="../checksums/">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="icon" href="../assets/images/favicon.png">
|
||||||
|
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.23">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<title>Hashing - Enchantrix</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../assets/stylesheets/main.84d31ad4.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||||
|
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<body dir="ltr">
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||||
|
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||||
|
<label class="md-overlay" for="__drawer"></label>
|
||||||
|
<div data-md-component="skip">
|
||||||
|
|
||||||
|
|
||||||
|
<a href="#hashing" class="md-skip">
|
||||||
|
Skip to content
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div data-md-component="announce">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<header class="md-header md-header--shadow" data-md-component="header">
|
||||||
|
<nav class="md-header__inner md-grid" aria-label="Header">
|
||||||
|
<a href=".." title="Enchantrix" class="md-header__button md-logo" aria-label="Enchantrix" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
<label class="md-header__button md-icon" for="__drawer">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-header__title" data-md-component="header-title">
|
||||||
|
<div class="md-header__ellipsis">
|
||||||
|
<div class="md-header__topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Enchantrix
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="md-header__topic" data-md-component="header-topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
|
||||||
|
Hashing
|
||||||
|
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" for="__search">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
|
<label class="md-search__overlay" for="__search"></label>
|
||||||
|
<div class="md-search__inner" role="search">
|
||||||
|
<form class="md-search__form" name="search">
|
||||||
|
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
|
||||||
|
<label class="md-search__icon md-icon" for="__search">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
|
||||||
|
</label>
|
||||||
|
<nav class="md-search__options" aria-label="Search">
|
||||||
|
|
||||||
|
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<div class="md-search__output">
|
||||||
|
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
|
||||||
|
<div class="md-search-result" data-md-component="search-result">
|
||||||
|
<div class="md-search-result__meta">
|
||||||
|
Initializing search
|
||||||
|
</div>
|
||||||
|
<ol class="md-search-result__list" role="presentation"></ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="md-container" data-md-component="container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<main class="md-main" data-md-component="main">
|
||||||
|
<div class="md-main__inner md-grid">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
|
||||||
|
<label class="md-nav__title" for="__drawer">
|
||||||
|
<a href=".." title="Enchantrix" class="md-nav__button md-logo" aria-label="Enchantrix" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
Enchantrix
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href=".." class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Home
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../trix_format/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix File Format
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" checked>
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Examples
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="true">
|
||||||
|
<label class="md-nav__title" for="__nav_3">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Examples
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../trix_and_sigils/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix & Sigil Chaining
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--active">
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="./" class="md-nav__link md-nav__link--active">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Hashing
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../checksums/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Checksums
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../rsa/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
RSA
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="../standalone_sigils/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Standalone Sigils
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-content" data-md-component="content">
|
||||||
|
<article class="md-content__inner md-typeset">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h1 id="hashing">Hashing</h1>
|
||||||
|
<p>This example demonstrates how to use the <code>crypt</code> service to hash a payload using various algorithms.</p>
|
||||||
|
<pre><code class="language-go">package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Snider/Enchantrix/pkg/crypt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func demoHashing() {
|
||||||
|
fmt.Println("--- Hashing Demo ---")
|
||||||
|
cryptService := crypt.NewService()
|
||||||
|
payload := "Enchantrix"
|
||||||
|
|
||||||
|
hashTypes := []crypt.HashType{
|
||||||
|
crypt.LTHN,
|
||||||
|
crypt.MD5,
|
||||||
|
crypt.SHA1,
|
||||||
|
crypt.SHA256,
|
||||||
|
crypt.SHA512,
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Payload to hash: \"%s\"\n", payload)
|
||||||
|
for _, hashType := range hashTypes {
|
||||||
|
hash := cryptService.Hash(hashType, payload)
|
||||||
|
fmt.Printf(" - %-6s: %s\n", hashType, hash)
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="md-footer">
|
||||||
|
|
||||||
|
<div class="md-footer-meta md-typeset">
|
||||||
|
<div class="md-footer-meta__inner md-grid">
|
||||||
|
<div class="md-copyright">
|
||||||
|
|
||||||
|
|
||||||
|
Made with
|
||||||
|
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||||
|
Material for MkDocs
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="md-dialog" data-md-component="dialog">
|
||||||
|
<div class="md-dialog__inner md-typeset"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script id="__config" type="application/json">{"base": "..", "features": [], "search": "../assets/javascripts/workers/search.973d3a69.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="../assets/javascripts/bundle.f55a23d4.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
580
index.html
Normal file
580
index.html
Normal file
|
|
@ -0,0 +1,580 @@
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en" class="no-js">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="next" href="trix_format/">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="icon" href="assets/images/favicon.png">
|
||||||
|
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.23">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<title>Enchantrix</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="assets/stylesheets/main.84d31ad4.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||||
|
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>__md_scope=new URL(".",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<body dir="ltr">
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||||
|
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||||
|
<label class="md-overlay" for="__drawer"></label>
|
||||||
|
<div data-md-component="skip">
|
||||||
|
|
||||||
|
|
||||||
|
<a href="#welcome-to-enchantrix" class="md-skip">
|
||||||
|
Skip to content
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div data-md-component="announce">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<header class="md-header md-header--shadow" data-md-component="header">
|
||||||
|
<nav class="md-header__inner md-grid" aria-label="Header">
|
||||||
|
<a href="." title="Enchantrix" class="md-header__button md-logo" aria-label="Enchantrix" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
<label class="md-header__button md-icon" for="__drawer">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-header__title" data-md-component="header-title">
|
||||||
|
<div class="md-header__ellipsis">
|
||||||
|
<div class="md-header__topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Enchantrix
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="md-header__topic" data-md-component="header-topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
|
||||||
|
Home
|
||||||
|
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" for="__search">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
|
<label class="md-search__overlay" for="__search"></label>
|
||||||
|
<div class="md-search__inner" role="search">
|
||||||
|
<form class="md-search__form" name="search">
|
||||||
|
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
|
||||||
|
<label class="md-search__icon md-icon" for="__search">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
|
||||||
|
</label>
|
||||||
|
<nav class="md-search__options" aria-label="Search">
|
||||||
|
|
||||||
|
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<div class="md-search__output">
|
||||||
|
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
|
||||||
|
<div class="md-search-result" data-md-component="search-result">
|
||||||
|
<div class="md-search-result__meta">
|
||||||
|
Initializing search
|
||||||
|
</div>
|
||||||
|
<ol class="md-search-result__list" role="presentation"></ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="md-container" data-md-component="container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<main class="md-main" data-md-component="main">
|
||||||
|
<div class="md-main__inner md-grid">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
|
||||||
|
<label class="md-nav__title" for="__drawer">
|
||||||
|
<a href="." title="Enchantrix" class="md-nav__button md-logo" aria-label="Enchantrix" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
Enchantrix
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--active">
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Home
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<a href="." class="md-nav__link md-nav__link--active">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Home
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__title" for="__toc">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Table of contents
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#trix-file-format" class="md-nav__link">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix File Format
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#examples" class="md-nav__link">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Examples
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="trix_format/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix File Format
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--nested">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Examples
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
|
||||||
|
<label class="md-nav__title" for="__nav_3">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Examples
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="trix_and_sigils/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix & Sigil Chaining
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="hashing/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Hashing
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="checksums/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Checksums
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="rsa/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
RSA
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="standalone_sigils/" class="md-nav__link">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Standalone Sigils
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__title" for="__toc">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Table of contents
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#trix-file-format" class="md-nav__link">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Trix File Format
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#examples" class="md-nav__link">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Examples
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-content" data-md-component="content">
|
||||||
|
<article class="md-content__inner md-typeset">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h1 id="welcome-to-enchantrix">Welcome to Enchantrix</h1>
|
||||||
|
<p>Enchantrix is a Go-based crypto library and miner application. This documentation provides information on how to use the various features of the Enchantrix library.</p>
|
||||||
|
<h2 id="trix-file-format">Trix File Format</h2>
|
||||||
|
<p>The <code>.trix</code> file format is a generic and flexible binary container for storing an arbitrary data payload alongside structured metadata. For more information, see the <a href="trix_format/">Trix File Format</a> page.</p>
|
||||||
|
<h2 id="examples">Examples</h2>
|
||||||
|
<p>The following pages provide examples of how to use the Enchantrix library:</p>
|
||||||
|
<ul>
|
||||||
|
<li><a href="trix_and_sigils/">Trix & Sigil Chaining</a></li>
|
||||||
|
<li><a href="hashing/">Hashing</a></li>
|
||||||
|
<li><a href="checksums/">Checksums</a></li>
|
||||||
|
<li><a href="rsa/">RSA</a></li>
|
||||||
|
<li><a href="standalone_sigils/">Standalone Sigils</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="md-footer">
|
||||||
|
|
||||||
|
<div class="md-footer-meta md-typeset">
|
||||||
|
<div class="md-footer-meta__inner md-grid">
|
||||||
|
<div class="md-copyright">
|
||||||
|
|
||||||
|
|
||||||
|
Made with
|
||||||
|
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||||
|
Material for MkDocs
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="md-dialog" data-md-component="dialog">
|
||||||
|
<div class="md-dialog__inner md-typeset"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script id="__config" type="application/json">{"base": ".", "features": [], "search": "assets/javascripts/workers/search.973d3a69.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="assets/javascripts/bundle.f55a23d4.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
24
mkdocs.yml
24
mkdocs.yml
|
|
@ -1,24 +0,0 @@
|
||||||
site_name: Enchantrix
|
|
||||||
site_description: Go encryption library and Trix file format
|
|
||||||
site_url: https://github.com/Snider/Enchantrix
|
|
||||||
repo_url: https://github.com/Snider/Enchantrix
|
|
||||||
repo_name: Snider/Enchantrix
|
|
||||||
docs_dir: docs
|
|
||||||
theme:
|
|
||||||
name: material
|
|
||||||
nav:
|
|
||||||
- Home: index.md
|
|
||||||
- Trix File Format: trix_format.md
|
|
||||||
- CLI Reference: cli.md
|
|
||||||
- Examples:
|
|
||||||
- Trix & Sigil Chaining: trix_and_sigils.md
|
|
||||||
- Hashing: hashing.md
|
|
||||||
- Checksums: checksums.md
|
|
||||||
- RSA: rsa.md
|
|
||||||
- PGP: pgp.md
|
|
||||||
- Standalone Sigils: standalone_sigils.md
|
|
||||||
markdown_extensions:
|
|
||||||
- admonition
|
|
||||||
- codehilite
|
|
||||||
- toc:
|
|
||||||
permalink: true
|
|
||||||
|
|
@ -1,243 +0,0 @@
|
||||||
package crypt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/md5"
|
|
||||||
"crypto/sha1"
|
|
||||||
"errors"
|
|
||||||
"crypto/sha256"
|
|
||||||
"crypto/sha512"
|
|
||||||
"encoding/binary"
|
|
||||||
"encoding/hex"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt/std/lthn"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt/std/pgp"
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt/std/rsa"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Service is the main struct for the crypt service.
|
|
||||||
// It provides methods for hashing, checksums, and encryption.
|
|
||||||
type Service struct {
|
|
||||||
rsa *rsa.Service
|
|
||||||
pgp *pgp.Service
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewService creates a new crypt Service and initialises its embedded services.
|
|
||||||
// It returns a new Service.
|
|
||||||
func NewService() *Service {
|
|
||||||
return &Service{
|
|
||||||
rsa: rsa.NewService(),
|
|
||||||
pgp: pgp.NewService(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HashType defines the supported hashing algorithms.
|
|
||||||
type HashType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
// LTHN is a custom quasi-salted hashing algorithm.
|
|
||||||
LTHN HashType = "lthn"
|
|
||||||
// SHA512 is the SHA-512 hashing algorithm.
|
|
||||||
SHA512 HashType = "sha512"
|
|
||||||
// SHA256 is the SHA-256 hashing algorithm.
|
|
||||||
SHA256 HashType = "sha256"
|
|
||||||
// SHA1 is the SHA-1 hashing algorithm.
|
|
||||||
SHA1 HashType = "sha1"
|
|
||||||
// MD5 is the MD5 hashing algorithm.
|
|
||||||
MD5 HashType = "md5"
|
|
||||||
)
|
|
||||||
|
|
||||||
// --- Hashing ---
|
|
||||||
|
|
||||||
// IsHashAlgo checks if a string is a valid hash algorithm.
|
|
||||||
func (s *Service) IsHashAlgo(algo string) bool {
|
|
||||||
switch HashType(algo) {
|
|
||||||
case LTHN, SHA512, SHA256, SHA1, MD5:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash computes a hash of the payload using the specified algorithm.
|
|
||||||
// It returns the hash as a hex-encoded string.
|
|
||||||
func (s *Service) Hash(lib HashType, payload string) string {
|
|
||||||
switch lib {
|
|
||||||
case LTHN:
|
|
||||||
return lthn.Hash(payload)
|
|
||||||
case SHA512:
|
|
||||||
hash := sha512.Sum512([]byte(payload))
|
|
||||||
return hex.EncodeToString(hash[:])
|
|
||||||
case SHA1:
|
|
||||||
hash := sha1.Sum([]byte(payload))
|
|
||||||
return hex.EncodeToString(hash[:])
|
|
||||||
case MD5:
|
|
||||||
hash := md5.Sum([]byte(payload))
|
|
||||||
return hex.EncodeToString(hash[:])
|
|
||||||
case SHA256:
|
|
||||||
fallthrough
|
|
||||||
default:
|
|
||||||
hash := sha256.Sum256([]byte(payload))
|
|
||||||
return hex.EncodeToString(hash[:])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Checksums ---
|
|
||||||
|
|
||||||
// Luhn validates a number using the Luhn algorithm.
|
|
||||||
// It is typically used to validate credit card numbers.
|
|
||||||
func (s *Service) Luhn(payload string) bool {
|
|
||||||
payload = strings.ReplaceAll(payload, " ", "")
|
|
||||||
if len(payload) <= 1 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
sum := 0
|
|
||||||
isSecond := len(payload)%2 == 0
|
|
||||||
for _, r := range payload {
|
|
||||||
digit, err := strconv.Atoi(string(r))
|
|
||||||
if err != nil {
|
|
||||||
return false // Contains non-digit
|
|
||||||
}
|
|
||||||
|
|
||||||
if isSecond {
|
|
||||||
digit = digit * 2
|
|
||||||
if digit > 9 {
|
|
||||||
digit = digit - 9
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sum += digit
|
|
||||||
isSecond = !isSecond
|
|
||||||
}
|
|
||||||
return sum%10 == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fletcher16 computes the Fletcher-16 checksum.
|
|
||||||
// It is a fast checksum algorithm that is more reliable than a simple sum.
|
|
||||||
func (s *Service) Fletcher16(payload string) uint16 {
|
|
||||||
data := []byte(payload)
|
|
||||||
var sum1, sum2 uint16
|
|
||||||
for _, b := range data {
|
|
||||||
sum1 = (sum1 + uint16(b)) % 255
|
|
||||||
sum2 = (sum2 + sum1) % 255
|
|
||||||
}
|
|
||||||
return (sum2 << 8) | sum1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fletcher32 computes the Fletcher-32 checksum.
|
|
||||||
// It provides better error detection than Fletcher-16.
|
|
||||||
func (s *Service) Fletcher32(payload string) uint32 {
|
|
||||||
data := []byte(payload)
|
|
||||||
if len(data)%2 != 0 {
|
|
||||||
data = append(data, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
var sum1, sum2 uint32
|
|
||||||
for i := 0; i < len(data); i += 2 {
|
|
||||||
val := binary.LittleEndian.Uint16(data[i : i+2])
|
|
||||||
sum1 = (sum1 + uint32(val)) % 65535
|
|
||||||
sum2 = (sum2 + sum1) % 65535
|
|
||||||
}
|
|
||||||
return (sum2 << 16) | sum1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fletcher64 computes the Fletcher-64 checksum.
|
|
||||||
// It provides the best error detection of the Fletcher algorithms.
|
|
||||||
func (s *Service) Fletcher64(payload string) uint64 {
|
|
||||||
data := []byte(payload)
|
|
||||||
if len(data)%4 != 0 {
|
|
||||||
padding := 4 - (len(data) % 4)
|
|
||||||
data = append(data, make([]byte, padding)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
var sum1, sum2 uint64
|
|
||||||
for i := 0; i < len(data); i += 4 {
|
|
||||||
val := binary.LittleEndian.Uint32(data[i : i+4])
|
|
||||||
sum1 = (sum1 + uint64(val)) % 4294967295
|
|
||||||
sum2 = (sum2 + sum1) % 4294967295
|
|
||||||
}
|
|
||||||
return (sum2 << 32) | sum1
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- RSA ---
|
|
||||||
|
|
||||||
// ensureRSA initializes the RSA service if it is not already.
|
|
||||||
func (s *Service) ensureRSA() {
|
|
||||||
if s.rsa == nil {
|
|
||||||
s.rsa = rsa.NewService()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateRSAKeyPair creates a new RSA key pair.
|
|
||||||
func (s *Service) GenerateRSAKeyPair(bits int) (publicKey, privateKey []byte, err error) {
|
|
||||||
s.ensureRSA()
|
|
||||||
return s.rsa.GenerateKeyPair(bits)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncryptRSA encrypts data with a public key.
|
|
||||||
func (s *Service) EncryptRSA(publicKey, data, label []byte) ([]byte, error) {
|
|
||||||
s.ensureRSA()
|
|
||||||
return s.rsa.Encrypt(publicKey, data, label)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecryptRSA decrypts data with a private key.
|
|
||||||
func (s *Service) DecryptRSA(privateKey, ciphertext, label []byte) ([]byte, error) {
|
|
||||||
s.ensureRSA()
|
|
||||||
return s.rsa.Decrypt(privateKey, ciphertext, label)
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- PGP ---
|
|
||||||
|
|
||||||
// ensurePGP initializes the PGP service if it is not already.
|
|
||||||
func (s *Service) ensurePGP() {
|
|
||||||
if s.pgp == nil {
|
|
||||||
s.pgp = pgp.NewService()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GeneratePGPKeyPair creates a new PGP key pair.
|
|
||||||
// It returns the public and private keys in PEM format.
|
|
||||||
func (s *Service) GeneratePGPKeyPair(name, email, comment string) (publicKey, privateKey []byte, err error) {
|
|
||||||
s.ensurePGP()
|
|
||||||
return s.pgp.GenerateKeyPair(name, email, comment)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncryptPGP encrypts data with a public key.
|
|
||||||
// It returns the encrypted data.
|
|
||||||
func (s *Service) EncryptPGP(publicKey, data []byte) ([]byte, error) {
|
|
||||||
s.ensurePGP()
|
|
||||||
return s.pgp.Encrypt(publicKey, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecryptPGP decrypts data with a private key.
|
|
||||||
// It returns the decrypted data.
|
|
||||||
func (s *Service) DecryptPGP(privateKey, ciphertext []byte) ([]byte, error) {
|
|
||||||
s.ensurePGP()
|
|
||||||
return s.pgp.Decrypt(privateKey, ciphertext)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignPGP creates a detached signature for a message.
|
|
||||||
// It returns the signature.
|
|
||||||
func (s *Service) SignPGP(privateKey, data []byte) ([]byte, error) {
|
|
||||||
s.ensurePGP()
|
|
||||||
return s.pgp.Sign(privateKey, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// VerifyPGP verifies a detached signature for a message.
|
|
||||||
// It returns an error if the signature is invalid.
|
|
||||||
func (s *Service) VerifyPGP(publicKey, data, signature []byte) error {
|
|
||||||
s.ensurePGP()
|
|
||||||
return s.pgp.Verify(publicKey, data, signature)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SymmetricallyEncryptPGP encrypts data with a passphrase.
|
|
||||||
// It returns the encrypted data.
|
|
||||||
func (s *Service) SymmetricallyEncryptPGP(passphrase, data []byte) ([]byte, error) {
|
|
||||||
s.ensurePGP()
|
|
||||||
if len(passphrase) == 0 {
|
|
||||||
return nil, errors.New("passphrase cannot be empty")
|
|
||||||
}
|
|
||||||
return s.pgp.SymmetricallyEncrypt(passphrase, data)
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package crypt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestEnsureRSA_Good tests that the RSA service is initialized correctly.
|
|
||||||
func TestEnsureRSA_Good(t *testing.T) {
|
|
||||||
s := &Service{}
|
|
||||||
s.ensureRSA()
|
|
||||||
assert.NotNil(t, s.rsa)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestEnsureRSA_Bad tests that calling ensureRSA multiple times does not change the RSA service.
|
|
||||||
func TestEnsureRSA_Bad(t *testing.T) {
|
|
||||||
s := &Service{}
|
|
||||||
s.ensureRSA()
|
|
||||||
rsa1 := s.rsa
|
|
||||||
s.ensureRSA()
|
|
||||||
rsa2 := s.rsa
|
|
||||||
assert.Same(t, rsa1, rsa2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestEnsureRSA_Ugly tests that ensureRSA works correctly on a service with a pre-initialized RSA service.
|
|
||||||
func TestEnsureRSA_Ugly(t *testing.T) {
|
|
||||||
s := NewService() // NewService initializes the RSA service
|
|
||||||
rsa1 := s.rsa
|
|
||||||
s.ensureRSA()
|
|
||||||
rsa2 := s.rsa
|
|
||||||
assert.Same(t, rsa1, rsa2)
|
|
||||||
}
|
|
||||||
|
|
@ -1,271 +0,0 @@
|
||||||
package crypt_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
var service = crypt.NewService()
|
|
||||||
|
|
||||||
// --- Hashing Tests ---
|
|
||||||
|
|
||||||
func TestHash_Good(t *testing.T) {
|
|
||||||
payload := "hello"
|
|
||||||
// Test all supported hash types
|
|
||||||
for _, hashType := range []crypt.HashType{crypt.LTHN, crypt.SHA512, crypt.SHA256, crypt.SHA1, crypt.MD5} {
|
|
||||||
hash := service.Hash(hashType, payload)
|
|
||||||
assert.NotEmpty(t, hash, "Hash should not be empty for type %s", hashType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHash_Bad(t *testing.T) {
|
|
||||||
// Using an unsupported hash type should default to SHA256
|
|
||||||
hash := service.Hash("unsupported", "hello")
|
|
||||||
expectedHash := service.Hash(crypt.SHA256, "hello")
|
|
||||||
assert.Equal(t, expectedHash, hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHash_Ugly(t *testing.T) {
|
|
||||||
// Test with potentially problematic inputs
|
|
||||||
testCases := []string{
|
|
||||||
"", // Empty string
|
|
||||||
" ", // Whitespace
|
|
||||||
"\x00\x01\x02\x03\x04", // Null bytes
|
|
||||||
strings.Repeat("a", 1024*1024), // Large payload (1MB)
|
|
||||||
"こんにちは", // Unicode characters
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range testCases {
|
|
||||||
for _, hashType := range []crypt.HashType{crypt.LTHN, crypt.SHA512, crypt.SHA256, crypt.SHA1, crypt.MD5} {
|
|
||||||
hash := service.Hash(hashType, tc)
|
|
||||||
assert.NotEmpty(t, hash, "Hash for ugly input should not be empty for type %s", hashType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Checksum Tests ---
|
|
||||||
|
|
||||||
// Luhn Tests
|
|
||||||
func TestLuhn_Good(t *testing.T) {
|
|
||||||
assert.True(t, service.Luhn("79927398713"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLuhn_Bad(t *testing.T) {
|
|
||||||
assert.False(t, service.Luhn("79927398714"), "Should fail for incorrect checksum")
|
|
||||||
assert.False(t, service.Luhn("7992739871a"), "Should fail for non-numeric input")
|
|
||||||
assert.False(t, service.Luhn("1"), "Should be false for single digit")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLuhn_Ugly(t *testing.T) {
|
|
||||||
assert.False(t, service.Luhn(""), "Should be false for empty string")
|
|
||||||
assert.False(t, service.Luhn(" 1 2 3 "), "Should handle spaces but result in false")
|
|
||||||
assert.False(t, service.Luhn("!@#$%^&*()"), "Should be false for special characters")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fletcher16 Tests
|
|
||||||
func TestFletcher16_Good(t *testing.T) {
|
|
||||||
assert.Equal(t, uint16(0xC8F0), service.Fletcher16("abcde"))
|
|
||||||
assert.Equal(t, uint16(0x2057), service.Fletcher16("abcdef"))
|
|
||||||
assert.Equal(t, uint16(0x0627), service.Fletcher16("abcdefgh"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFletcher16_Ugly(t *testing.T) {
|
|
||||||
assert.Equal(t, uint16(0), service.Fletcher16(""), "Checksum of empty string should be 0")
|
|
||||||
assert.Equal(t, uint16(0), service.Fletcher16("\x00"), "Checksum of null byte should be 0")
|
|
||||||
assert.NotEqual(t, uint16(0), service.Fletcher16(" "), "Checksum of space should not be 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fletcher32 Tests
|
|
||||||
func TestFletcher32_Good(t *testing.T) {
|
|
||||||
assert.Equal(t, uint32(0xF04FC729), service.Fletcher32("abcde"))
|
|
||||||
assert.Equal(t, uint32(0x56502D2A), service.Fletcher32("abcdef"))
|
|
||||||
assert.Equal(t, uint32(0xEBE19591), service.Fletcher32("abcdefgh"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFletcher32_Ugly(t *testing.T) {
|
|
||||||
assert.Equal(t, uint32(0), service.Fletcher32(""), "Checksum of empty string should be 0")
|
|
||||||
// Test odd length string to check padding
|
|
||||||
assert.NotEqual(t, uint32(0), service.Fletcher32("a"), "Checksum of odd length string")
|
|
||||||
assert.NotEqual(t, uint32(0), service.Fletcher32(" "), "Checksum of space should not be 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fletcher64 Tests
|
|
||||||
func TestFletcher64_Good(t *testing.T) {
|
|
||||||
assert.Equal(t, uint64(0xc8c6c527646362c6), service.Fletcher64("abcde"))
|
|
||||||
assert.Equal(t, uint64(0xc8c72b276463c8c6), service.Fletcher64("abcdef"))
|
|
||||||
assert.Equal(t, uint64(0x312e2b28cccac8c6), service.Fletcher64("abcdefgh"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFletcher64_Ugly(t *testing.T) {
|
|
||||||
assert.Equal(t, uint64(0), service.Fletcher64(""), "Checksum of empty string should be 0")
|
|
||||||
// Test different length strings to check padding
|
|
||||||
assert.NotEqual(t, uint64(0), service.Fletcher64("a"), "Checksum of length 1 string")
|
|
||||||
assert.NotEqual(t, uint64(0), service.Fletcher64("ab"), "Checksum of length 2 string")
|
|
||||||
assert.NotEqual(t, uint64(0), service.Fletcher64("abc"), "Checksum of length 3 string")
|
|
||||||
assert.NotEqual(t, uint64(0), service.Fletcher64(" "), "Checksum of space should not be 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- RSA Tests ---
|
|
||||||
|
|
||||||
func TestRSA_Good(t *testing.T) {
|
|
||||||
pubKey, privKey, err := service.GenerateRSAKeyPair(2048)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotNil(t, pubKey)
|
|
||||||
assert.NotNil(t, privKey)
|
|
||||||
|
|
||||||
// Test encryption and decryption
|
|
||||||
message := []byte("secret message")
|
|
||||||
label := []byte("test label")
|
|
||||||
ciphertext, err := service.EncryptRSA(pubKey, message, label)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
plaintext, err := service.DecryptRSA(privKey, ciphertext, label)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, message, plaintext)
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- PGP Tests ---
|
|
||||||
|
|
||||||
func TestPGP_Good(t *testing.T) {
|
|
||||||
pubKey, privKey, err := service.GeneratePGPKeyPair("test", "test@test.com", "test comment")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotNil(t, pubKey)
|
|
||||||
assert.NotNil(t, privKey)
|
|
||||||
|
|
||||||
// Test encryption and decryption
|
|
||||||
message := []byte("secret message")
|
|
||||||
ciphertext, err := service.EncryptPGP(pubKey, message)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
plaintext, err := service.DecryptPGP(privKey, ciphertext)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, message, plaintext)
|
|
||||||
|
|
||||||
// Test signing and verification
|
|
||||||
signature, err := service.SignPGP(privKey, message)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
err = service.VerifyPGP(pubKey, message, signature)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// Test symmetric encryption
|
|
||||||
passphrase := []byte("my-secret-passphrase")
|
|
||||||
ciphertext, err = service.SymmetricallyEncryptPGP(passphrase, message)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotNil(t, ciphertext)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPGP_Bad(t *testing.T) {
|
|
||||||
// Generate two key pairs
|
|
||||||
pubKey1, privKey1, err := service.GeneratePGPKeyPair("test1", "test1@test.com", "")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
pubKey2, privKey2, err := service.GeneratePGPKeyPair("test2", "test2@test.com", "")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
message := []byte("secret message")
|
|
||||||
|
|
||||||
// Test decryption with the wrong key
|
|
||||||
ciphertext, err := service.EncryptPGP(pubKey1, message)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
// This should fail because we are using the wrong private key.
|
|
||||||
_, err = service.DecryptPGP(privKey2, ciphertext) // Intentionally using wrong key
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test verification with the wrong key
|
|
||||||
signature, err := service.SignPGP(privKey1, message)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
err = service.VerifyPGP(pubKey2, message, signature)
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test verification with a tampered message
|
|
||||||
tamperedMessage := []byte("tampered message")
|
|
||||||
err = service.VerifyPGP(pubKey1, tamperedMessage, signature)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPGP_Ugly(t *testing.T) {
|
|
||||||
// Test with malformed keys
|
|
||||||
_, err := service.EncryptPGP([]byte("not a real key"), []byte("message"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
_, err = service.DecryptPGP([]byte("not a real key"), []byte("message"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
_, err = service.SignPGP([]byte("not a real key"), []byte("message"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
err = service.VerifyPGP([]byte("not a real key"), []byte("message"), []byte("not a real signature"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test with empty message
|
|
||||||
pubKey, privKey, err := service.GeneratePGPKeyPair("test", "test@test.com", "")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
message := []byte("")
|
|
||||||
ciphertext, err := service.EncryptPGP(pubKey, message)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
plaintext, err := service.DecryptPGP(privKey, ciphertext, )
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, message, plaintext)
|
|
||||||
|
|
||||||
// Test symmetric encryption with empty passphrase
|
|
||||||
_, err = service.SymmetricallyEncryptPGP([]byte(""), message)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- IsHashAlgo Tests ---
|
|
||||||
|
|
||||||
func TestIsHashAlgo_Good(t *testing.T) {
|
|
||||||
assert.True(t, service.IsHashAlgo("lthn"))
|
|
||||||
assert.True(t, service.IsHashAlgo("sha512"))
|
|
||||||
assert.True(t, service.IsHashAlgo("sha256"))
|
|
||||||
assert.True(t, service.IsHashAlgo("sha1"))
|
|
||||||
assert.True(t, service.IsHashAlgo("md5"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIsHashAlgo_Bad(t *testing.T) {
|
|
||||||
assert.False(t, service.IsHashAlgo("not-a-hash"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRSA_Bad(t *testing.T) {
|
|
||||||
// Test with a key size that is too small
|
|
||||||
_, _, err := service.GenerateRSAKeyPair(1024)
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test decryption with the wrong key
|
|
||||||
pubKey, privKey, err := service.GenerateRSAKeyPair(2048)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
_, otherPrivKey, err := service.GenerateRSAKeyPair(2048)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
message := []byte("secret message")
|
|
||||||
ciphertext, err := service.EncryptRSA(pubKey, message, nil)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
_, err = service.DecryptRSA(otherPrivKey, ciphertext, nil)
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test decryption with wrong label
|
|
||||||
label1 := []byte("label1")
|
|
||||||
label2 := []byte("label2")
|
|
||||||
ciphertext, err = service.EncryptRSA(pubKey, message, label1)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
_, err = service.DecryptRSA(privKey, ciphertext, label2)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRSA_Ugly(t *testing.T) {
|
|
||||||
// Test with malformed keys
|
|
||||||
_, err := service.EncryptRSA([]byte("not a real key"), []byte("message"), nil)
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
_, err = service.DecryptRSA([]byte("not a real key"), []byte("message"), nil)
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test with empty message
|
|
||||||
pubKey, privKey, err := service.GenerateRSAKeyPair(2048)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
message := []byte("")
|
|
||||||
ciphertext, err := service.EncryptRSA(pubKey, message, nil)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
plaintext, err := service.DecryptRSA(privKey, ciphertext, nil)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, message, plaintext)
|
|
||||||
}
|
|
||||||
|
|
@ -1,170 +0,0 @@
|
||||||
package crypt_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/Snider/Enchantrix/pkg/crypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ExampleService_Hash() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
payload := "Enchantrix"
|
|
||||||
|
|
||||||
hashTypes := []crypt.HashType{
|
|
||||||
crypt.LTHN,
|
|
||||||
crypt.MD5,
|
|
||||||
crypt.SHA1,
|
|
||||||
crypt.SHA256,
|
|
||||||
crypt.SHA512,
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Payload to hash: \"%s\"\n", payload)
|
|
||||||
for _, hashType := range hashTypes {
|
|
||||||
hash := cryptService.Hash(hashType, payload)
|
|
||||||
fmt.Printf(" - %-6s: %s\n", hashType, hash)
|
|
||||||
}
|
|
||||||
// Output:
|
|
||||||
// Payload to hash: "Enchantrix"
|
|
||||||
// - lthn : 331f24f86375846ac8d0d06cfb80cb2877e8900548a88d4ac8d39177cd854dab
|
|
||||||
// - md5 : 7c54903a10f058a93fd1f21ea802cb27
|
|
||||||
// - sha1 : 399f776c4b97e558a2c4f319b223dd481c6d43f1
|
|
||||||
// - sha256: 2ae653f74554abfdb2343013925f5184a0f05e4c2e0c3881448fc80caeb667c2
|
|
||||||
// - sha512: 9638018a9720b5d83fba7f3899e4ba5ab78018781f9c600f0c0738ff8ccf1ea54e1c783ee8778542b70aa26283d87ce88784b2df5697322546d3b8029c4b6797
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_Luhn() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
luhnPayloadGood := "49927398716"
|
|
||||||
luhnPayloadBad := "49927398717"
|
|
||||||
fmt.Printf("Luhn Checksum:\n")
|
|
||||||
fmt.Printf(" - Payload '%s' is valid: %v\n", luhnPayloadGood, cryptService.Luhn(luhnPayloadGood))
|
|
||||||
fmt.Printf(" - Payload '%s' is valid: %v\n", luhnPayloadBad, cryptService.Luhn(luhnPayloadBad))
|
|
||||||
// Output:
|
|
||||||
// Luhn Checksum:
|
|
||||||
// - Payload '49927398716' is valid: true
|
|
||||||
// - Payload '49927398717' is valid: false
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_Fletcher16() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
fletcherPayload := "abcde"
|
|
||||||
fmt.Printf("Fletcher16 Checksum (Payload: \"%s\"): %d\n", fletcherPayload, cryptService.Fletcher16(fletcherPayload))
|
|
||||||
// Output:
|
|
||||||
// Fletcher16 Checksum (Payload: "abcde"): 51440
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_Fletcher32() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
fletcherPayload := "abcde"
|
|
||||||
fmt.Printf("Fletcher32 Checksum (Payload: \"%s\"): %d\n", fletcherPayload, cryptService.Fletcher32(fletcherPayload))
|
|
||||||
// Output:
|
|
||||||
// Fletcher32 Checksum (Payload: "abcde"): 4031760169
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_Fletcher64() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
fletcherPayload := "abcde"
|
|
||||||
fmt.Printf("Fletcher64 Checksum (Payload: \"%s\"): %d\n", fletcherPayload, cryptService.Fletcher64(fletcherPayload))
|
|
||||||
// Output:
|
|
||||||
// Fletcher64 Checksum (Payload: "abcde"): 14467467625952928454
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_GeneratePGPKeyPair() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
publicKey, privateKey, err := cryptService.GeneratePGPKeyPair("test", "test@example.com", "test key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("PGP public key is not empty: %v\n", len(publicKey) > 0)
|
|
||||||
fmt.Printf("PGP private key is not empty: %v\n", len(privateKey) > 0)
|
|
||||||
// Output:
|
|
||||||
// PGP public key is not empty: true
|
|
||||||
// PGP private key is not empty: true
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_EncryptPGP() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
publicKey, _, err := cryptService.GeneratePGPKeyPair("test", "test@example.com", "test key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
message := []byte("This is a secret message for PGP.")
|
|
||||||
ciphertext, err := cryptService.EncryptPGP(publicKey, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("PGP ciphertext is not empty: %v\n", len(ciphertext) > 0)
|
|
||||||
// Output:
|
|
||||||
// PGP ciphertext is not empty: true
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_DecryptPGP() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
publicKey, privateKey, err := cryptService.GeneratePGPKeyPair("test", "test@example.com", "test key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
message := []byte("This is a secret message for PGP.")
|
|
||||||
ciphertext, err := cryptService.EncryptPGP(publicKey, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to encrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
decrypted, err := cryptService.DecryptPGP(privateKey, ciphertext)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to decrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Decrypted message: %s\n", decrypted)
|
|
||||||
// Output:
|
|
||||||
// Decrypted message: This is a secret message for PGP.
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_SignPGP() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
_, privateKey, err := cryptService.GeneratePGPKeyPair("test", "test@example.com", "test key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
message := []byte("This is a message to be signed.")
|
|
||||||
signature, err := cryptService.SignPGP(privateKey, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to sign with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("PGP signature is not empty: %v\n", len(signature) > 0)
|
|
||||||
// Output:
|
|
||||||
// PGP signature is not empty: true
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_VerifyPGP() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
publicKey, privateKey, err := cryptService.GeneratePGPKeyPair("test", "test@example.com", "test key")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to generate PGP key pair: %v", err)
|
|
||||||
}
|
|
||||||
message := []byte("This is a message to be signed.")
|
|
||||||
signature, err := cryptService.SignPGP(privateKey, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to sign with PGP: %v", err)
|
|
||||||
}
|
|
||||||
err = cryptService.VerifyPGP(publicKey, message, signature)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("PGP signature verification failed.")
|
|
||||||
} else {
|
|
||||||
fmt.Println("PGP signature verified successfully.")
|
|
||||||
}
|
|
||||||
// Output:
|
|
||||||
// PGP signature verified successfully.
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleService_SymmetricallyEncryptPGP() {
|
|
||||||
cryptService := crypt.NewService()
|
|
||||||
passphrase := []byte("my secret passphrase")
|
|
||||||
message := []byte("This is a symmetric secret.")
|
|
||||||
ciphertext, err := cryptService.SymmetricallyEncryptPGP(passphrase, message)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to symmetrically encrypt with PGP: %v", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Symmetric PGP ciphertext is not empty: %v\n", len(ciphertext) > 0)
|
|
||||||
// Output:
|
|
||||||
// Symmetric PGP ciphertext is not empty: true
|
|
||||||
}
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
package chachapoly
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/rand"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/chacha20poly1305"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Encrypt encrypts data using ChaCha20-Poly1305.
|
|
||||||
func Encrypt(plaintext []byte, key []byte) ([]byte, error) {
|
|
||||||
aead, err := chacha20poly1305.NewX(key)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
nonce := make([]byte, aead.NonceSize(), aead.NonceSize()+len(plaintext)+aead.Overhead())
|
|
||||||
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return aead.Seal(nonce, nonce, plaintext, nil), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decrypt decrypts data using ChaCha20-Poly1305.
|
|
||||||
func Decrypt(ciphertext []byte, key []byte) ([]byte, error) {
|
|
||||||
aead, err := chacha20poly1305.NewX(key)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
minLen := aead.NonceSize() + aead.Overhead()
|
|
||||||
if len(ciphertext) < minLen {
|
|
||||||
return nil, fmt.Errorf("ciphertext too short: got %d bytes, need at least %d bytes", len(ciphertext), minLen)
|
|
||||||
}
|
|
||||||
|
|
||||||
nonce, ciphertext := ciphertext[:aead.NonceSize()], ciphertext[aead.NonceSize():]
|
|
||||||
|
|
||||||
decrypted, err := aead.Open(nil, nonce, ciphertext, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(decrypted) == 0 {
|
|
||||||
return []byte{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return decrypted, nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,114 +0,0 @@
|
||||||
package chachapoly
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/rand"
|
|
||||||
"errors"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
// mockReader is a reader that returns an error.
|
|
||||||
type mockReader struct{}
|
|
||||||
|
|
||||||
func (r *mockReader) Read(p []byte) (n int, err error) {
|
|
||||||
return 0, errors.New("read error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncryptDecrypt(t *testing.T) {
|
|
||||||
key := make([]byte, 32)
|
|
||||||
for i := range key {
|
|
||||||
key[i] = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
plaintext := []byte("Hello, world!")
|
|
||||||
ciphertext, err := Encrypt(plaintext, key)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
decrypted, err := Decrypt(ciphertext, key)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
assert.Equal(t, plaintext, decrypted)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncryptInvalidKeySize(t *testing.T) {
|
|
||||||
key := make([]byte, 16) // Wrong size
|
|
||||||
plaintext := []byte("test")
|
|
||||||
_, err := Encrypt(plaintext, key)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDecryptWithWrongKey(t *testing.T) {
|
|
||||||
key1 := make([]byte, 32)
|
|
||||||
key2 := make([]byte, 32)
|
|
||||||
key2[0] = 1 // Different key
|
|
||||||
|
|
||||||
plaintext := []byte("secret")
|
|
||||||
ciphertext, err := Encrypt(plaintext, key1)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
_, err = Decrypt(ciphertext, key2)
|
|
||||||
assert.Error(t, err) // Should fail authentication
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDecryptTamperedCiphertext(t *testing.T) {
|
|
||||||
key := make([]byte, 32)
|
|
||||||
plaintext := []byte("secret")
|
|
||||||
ciphertext, err := Encrypt(plaintext, key)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// Tamper with the ciphertext
|
|
||||||
ciphertext[0] ^= 0xff
|
|
||||||
|
|
||||||
_, err = Decrypt(ciphertext, key)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncryptEmptyPlaintext(t *testing.T) {
|
|
||||||
key := make([]byte, 32)
|
|
||||||
plaintext := []byte("")
|
|
||||||
ciphertext, err := Encrypt(plaintext, key)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
decrypted, err := Decrypt(ciphertext, key)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
assert.Equal(t, plaintext, decrypted)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDecryptShortCiphertext(t *testing.T) {
|
|
||||||
key := make([]byte, 32)
|
|
||||||
shortCiphertext := []byte("short")
|
|
||||||
|
|
||||||
_, err := Decrypt(shortCiphertext, key)
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "too short")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCiphertextDiffersFromPlaintext(t *testing.T) {
|
|
||||||
key := make([]byte, 32)
|
|
||||||
plaintext := []byte("Hello, world!")
|
|
||||||
ciphertext, err := Encrypt(plaintext, key)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotEqual(t, plaintext, ciphertext)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncryptNonceError(t *testing.T) {
|
|
||||||
key := make([]byte, 32)
|
|
||||||
plaintext := []byte("test")
|
|
||||||
|
|
||||||
// Replace the rand.Reader with our mock reader
|
|
||||||
oldReader := rand.Reader
|
|
||||||
rand.Reader = &mockReader{}
|
|
||||||
defer func() { rand.Reader = oldReader }()
|
|
||||||
|
|
||||||
_, err := Encrypt(plaintext, key)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDecryptInvalidKeySize(t *testing.T) {
|
|
||||||
key := make([]byte, 16) // Wrong size
|
|
||||||
ciphertext := []byte("test")
|
|
||||||
_, err := Decrypt(ciphertext, key)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
// Package lthn implements the LTHN quasi-salted hash algorithm (RFC-0004).
|
|
||||||
//
|
|
||||||
// LTHN produces deterministic, verifiable hashes without requiring separate salt
|
|
||||||
// storage. The salt is derived from the input itself through:
|
|
||||||
// 1. Reversing the input string
|
|
||||||
// 2. Applying "leet speak" style character substitutions
|
|
||||||
//
|
|
||||||
// The final hash is: SHA256(input || derived_salt)
|
|
||||||
//
|
|
||||||
// This is suitable for content identifiers, cache keys, and deduplication.
|
|
||||||
// NOT suitable for password hashing - use bcrypt, Argon2, or scrypt instead.
|
|
||||||
//
|
|
||||||
// Example:
|
|
||||||
//
|
|
||||||
// hash := lthn.Hash("hello")
|
|
||||||
// valid := lthn.Verify("hello", hash) // true
|
|
||||||
package lthn
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/hex"
|
|
||||||
)
|
|
||||||
|
|
||||||
// keyMap defines the character substitutions for quasi-salt derivation.
|
|
||||||
// These are inspired by "leet speak" conventions for letter-number substitution.
|
|
||||||
// The mapping is bidirectional for most characters but NOT fully symmetric.
|
|
||||||
var keyMap = map[rune]rune{
|
|
||||||
'o': '0', // letter O -> zero
|
|
||||||
'l': '1', // letter L -> one
|
|
||||||
'e': '3', // letter E -> three
|
|
||||||
'a': '4', // letter A -> four
|
|
||||||
's': 'z', // letter S -> Z
|
|
||||||
't': '7', // letter T -> seven
|
|
||||||
'0': 'o', // zero -> letter O
|
|
||||||
'1': 'l', // one -> letter L
|
|
||||||
'3': 'e', // three -> letter E
|
|
||||||
'4': 'a', // four -> letter A
|
|
||||||
'7': 't', // seven -> letter T
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetKeyMap replaces the default character substitution map.
|
|
||||||
// Use this to customize the quasi-salt derivation for specific applications.
|
|
||||||
// Changes affect all subsequent Hash and Verify calls.
|
|
||||||
func SetKeyMap(newKeyMap map[rune]rune) {
|
|
||||||
keyMap = newKeyMap
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetKeyMap returns the current character substitution map.
|
|
||||||
func GetKeyMap() map[rune]rune {
|
|
||||||
return keyMap
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash computes the LTHN hash of the input string.
|
|
||||||
//
|
|
||||||
// The algorithm:
|
|
||||||
// 1. Derive a quasi-salt by reversing the input and applying character substitutions
|
|
||||||
// 2. Concatenate: input + salt
|
|
||||||
// 3. Compute SHA-256 of the concatenated string
|
|
||||||
// 4. Return the hex-encoded digest (64 characters, lowercase)
|
|
||||||
//
|
|
||||||
// The same input always produces the same hash, enabling verification
|
|
||||||
// without storing a separate salt value.
|
|
||||||
func Hash(input string) string {
|
|
||||||
salt := createSalt(input)
|
|
||||||
hash := sha256.Sum256([]byte(input + salt))
|
|
||||||
return hex.EncodeToString(hash[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
// createSalt derives a quasi-salt by reversing the input and applying substitutions.
|
|
||||||
// For example: "hello" -> reversed "olleh" -> substituted "011eh"
|
|
||||||
func createSalt(input string) string {
|
|
||||||
if input == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
runes := []rune(input)
|
|
||||||
salt := make([]rune, len(runes))
|
|
||||||
for i := 0; i < len(runes); i++ {
|
|
||||||
char := runes[len(runes)-1-i]
|
|
||||||
if replacement, ok := keyMap[char]; ok {
|
|
||||||
salt[i] = replacement
|
|
||||||
} else {
|
|
||||||
salt[i] = char
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string(salt)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify checks if an input string produces the given hash.
|
|
||||||
// Returns true if Hash(input) equals the provided hash value.
|
|
||||||
// Uses direct string comparison - for security-critical applications,
|
|
||||||
// consider using constant-time comparison.
|
|
||||||
func Verify(input string, hash string) bool {
|
|
||||||
return Hash(input) == hash
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
package lthn
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCreateSalt_Good(t *testing.T) {
|
|
||||||
// "hello" reversed: "olleh" -> "0113h"
|
|
||||||
expected := "0113h"
|
|
||||||
actual := createSalt("hello")
|
|
||||||
assert.Equal(t, expected, actual, "Salt should be correctly created for 'hello'")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateSalt_Bad(t *testing.T) {
|
|
||||||
// Test with an empty string
|
|
||||||
expected := ""
|
|
||||||
actual := createSalt("")
|
|
||||||
assert.Equal(t, expected, actual, "Salt for an empty string should be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateSalt_Ugly(t *testing.T) {
|
|
||||||
// Test with characters not in the keyMap
|
|
||||||
input := "world123"
|
|
||||||
// "world123" reversed: "321dlrow" -> "e2ld1r0w"
|
|
||||||
expected := "e2ld1r0w"
|
|
||||||
actual := createSalt(input)
|
|
||||||
assert.Equal(t, expected, actual, "Salt should handle characters not in the keyMap")
|
|
||||||
|
|
||||||
// Test with only characters in the keyMap
|
|
||||||
input = "oleta"
|
|
||||||
// "oleta" reversed: "atelo" -> "47310"
|
|
||||||
expected = "47310"
|
|
||||||
actual = createSalt(input)
|
|
||||||
assert.Equal(t, expected, actual, "Salt should correctly handle strings with only keyMap characters")
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package lthn
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
var testKeyMapMu sync.Mutex
|
|
||||||
|
|
||||||
func TestSetKeyMap(t *testing.T) {
|
|
||||||
testKeyMapMu.Lock()
|
|
||||||
originalKeyMap := GetKeyMap()
|
|
||||||
t.Cleanup(func() {
|
|
||||||
SetKeyMap(originalKeyMap)
|
|
||||||
testKeyMapMu.Unlock()
|
|
||||||
})
|
|
||||||
|
|
||||||
newKeyMap := map[rune]rune{
|
|
||||||
'a': 'b',
|
|
||||||
}
|
|
||||||
SetKeyMap(newKeyMap)
|
|
||||||
assert.Equal(t, newKeyMap, GetKeyMap())
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
package lthn
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHash(t *testing.T) {
|
|
||||||
hash := Hash("hello")
|
|
||||||
assert.NotEmpty(t, hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestVerify(t *testing.T) {
|
|
||||||
hash := Hash("hello")
|
|
||||||
assert.True(t, Verify("hello", hash))
|
|
||||||
assert.False(t, Verify("world", hash))
|
|
||||||
}
|
|
||||||
|
|
@ -1,206 +0,0 @@
|
||||||
|
|
||||||
package pgp
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/ProtonMail/go-crypto/openpgp"
|
|
||||||
"github.com/ProtonMail/go-crypto/openpgp/armor"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Service is a service for PGP operations.
|
|
||||||
type Service struct{}
|
|
||||||
|
|
||||||
var (
|
|
||||||
openpgpNewEntity = openpgp.NewEntity
|
|
||||||
openpgpReadArmoredKeyRing = openpgp.ReadArmoredKeyRing
|
|
||||||
openpgpEncrypt = openpgp.Encrypt
|
|
||||||
openpgpReadMessage = openpgp.ReadMessage
|
|
||||||
openpgpArmoredDetachSign = openpgp.ArmoredDetachSign
|
|
||||||
openpgpCheckArmoredDetachedSignature = openpgp.CheckArmoredDetachedSignature
|
|
||||||
openpgpSymmetricallyEncrypt = openpgp.SymmetricallyEncrypt
|
|
||||||
armorEncode = armor.Encode
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewService creates a new PGP Service.
|
|
||||||
func NewService() *Service {
|
|
||||||
return &Service{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateKeyPair generates a new PGP key pair.
|
|
||||||
func (s *Service) GenerateKeyPair(name, email, comment string) (publicKey, privateKey []byte, err error) {
|
|
||||||
entity, err := openpgpNewEntity(name, comment, email, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("failed to create new entity: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sign all the identities
|
|
||||||
for _, id := range entity.Identities {
|
|
||||||
_ = id.SelfSignature.SignUserId(id.UserId.Id, entity.PrimaryKey, entity.PrivateKey, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Public Key
|
|
||||||
pubKeyBuf := new(bytes.Buffer)
|
|
||||||
pubKeyWriter, err := armorEncode(pubKeyBuf, openpgp.PublicKeyType, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("failed to create armored public key writer: %w", err)
|
|
||||||
}
|
|
||||||
defer pubKeyWriter.Close()
|
|
||||||
if err := entity.Serialize(pubKeyWriter); err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("failed to serialize public key: %w", err)
|
|
||||||
}
|
|
||||||
// a tricky little bastard, this one. without closing the writer, the buffer is empty.
|
|
||||||
pubKeyWriter.Close()
|
|
||||||
|
|
||||||
// Private Key
|
|
||||||
privKeyBuf := new(bytes.Buffer)
|
|
||||||
privKeyWriter, err := armorEncode(privKeyBuf, openpgp.PrivateKeyType, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("failed to create armored private key writer: %w", err)
|
|
||||||
}
|
|
||||||
defer privKeyWriter.Close()
|
|
||||||
if err := entity.SerializePrivate(privKeyWriter, nil); err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("failed to serialize private key: %w", err)
|
|
||||||
}
|
|
||||||
// a tricky little bastard, this one. without closing the writer, the buffer is empty.
|
|
||||||
privKeyWriter.Close()
|
|
||||||
|
|
||||||
return pubKeyBuf.Bytes(), privKeyBuf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encrypt encrypts data with a public key.
|
|
||||||
func (s *Service) Encrypt(publicKey, data []byte) ([]byte, error) {
|
|
||||||
pubKeyReader := bytes.NewReader(publicKey)
|
|
||||||
keyring, err := openpgpReadArmoredKeyRing(pubKeyReader)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read public key ring: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
w, err := openpgpEncrypt(buf, keyring, nil, nil, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to create encryption writer: %w", err)
|
|
||||||
}
|
|
||||||
defer w.Close()
|
|
||||||
|
|
||||||
_, err = w.Write(data)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to write data to encryption writer: %w", err)
|
|
||||||
}
|
|
||||||
w.Close()
|
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decrypt decrypts data with a private key.
|
|
||||||
func (s *Service) Decrypt(privateKey, ciphertext []byte) ([]byte, error) {
|
|
||||||
privKeyReader := bytes.NewReader(privateKey)
|
|
||||||
keyring, err := openpgpReadArmoredKeyRing(privKeyReader)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read private key ring: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := bytes.NewReader(ciphertext)
|
|
||||||
md, err := openpgpReadMessage(buf, keyring, nil, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read message: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
plaintext, err := io.ReadAll(md.UnverifiedBody)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read plaintext: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return plaintext, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sign creates a detached signature for a message.
|
|
||||||
func (s *Service) Sign(privateKey, data []byte) ([]byte, error) {
|
|
||||||
privKeyReader := bytes.NewReader(privateKey)
|
|
||||||
keyring, err := openpgpReadArmoredKeyRing(privKeyReader)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read private key ring: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
signer := keyring[0]
|
|
||||||
if signer.PrivateKey == nil {
|
|
||||||
return nil, fmt.Errorf("private key not found in keyring")
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
err = openpgpArmoredDetachSign(buf, signer, bytes.NewReader(data), nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to sign message: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify verifies a detached signature for a message.
|
|
||||||
func (s *Service) Verify(publicKey, data, signature []byte) error {
|
|
||||||
pubKeyReader := bytes.NewReader(publicKey)
|
|
||||||
keyring, err := openpgpReadArmoredKeyRing(pubKeyReader)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to read public key ring: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = openpgpCheckArmoredDetachedSignature(keyring, bytes.NewReader(data), bytes.NewReader(signature), nil)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to verify signature: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SymmetricallyEncrypt encrypts data with a passphrase.
|
|
||||||
func (s *Service) SymmetricallyEncrypt(passphrase, data []byte) ([]byte, error) {
|
|
||||||
if len(passphrase) == 0 {
|
|
||||||
return nil, fmt.Errorf("passphrase cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
w, err := openpgpSymmetricallyEncrypt(buf, passphrase, nil, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to create symmetric encryption writer: %w", err)
|
|
||||||
}
|
|
||||||
defer w.Close()
|
|
||||||
|
|
||||||
_, err = w.Write(data)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to write data to symmetric encryption writer: %w", err)
|
|
||||||
}
|
|
||||||
w.Close()
|
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SymmetricallyDecrypt decrypts data with a passphrase.
|
|
||||||
func (s *Service) SymmetricallyDecrypt(passphrase, ciphertext []byte) ([]byte, error) {
|
|
||||||
if len(passphrase) == 0 {
|
|
||||||
return nil, fmt.Errorf("passphrase cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := bytes.NewReader(ciphertext)
|
|
||||||
failed := false
|
|
||||||
prompt := func(keys []openpgp.Key, symmetric bool) ([]byte, error) {
|
|
||||||
if failed {
|
|
||||||
return nil, fmt.Errorf("decryption failed")
|
|
||||||
}
|
|
||||||
failed = true
|
|
||||||
return passphrase, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
md, err := openpgpReadMessage(buf, nil, prompt, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read message: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
plaintext, err := io.ReadAll(md.UnverifiedBody)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read plaintext: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return plaintext, nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,417 +0,0 @@
|
||||||
|
|
||||||
package pgp
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/ProtonMail/go-crypto/openpgp"
|
|
||||||
"github.com/ProtonMail/go-crypto/openpgp/packet"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestService_GenerateKeyPair_Good(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
pub, priv, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
||||||
require.NoError(t, err, "failed to generate key pair")
|
|
||||||
assert.NotNil(t, pub, "public key is nil")
|
|
||||||
assert.NotNil(t, priv, "private key is nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_GenerateKeyPair_Bad(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
// Test with invalid name (null byte)
|
|
||||||
_, _, err := s.GenerateKeyPair("test\x00", "test@test.com", "test")
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Encrypt_Good(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
pub, _, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
||||||
require.NoError(t, err, "failed to generate key pair")
|
|
||||||
assert.NotNil(t, pub, "public key is nil")
|
|
||||||
|
|
||||||
data := []byte("hello world")
|
|
||||||
encrypted, err := s.Encrypt(pub, data)
|
|
||||||
require.NoError(t, err, "failed to encrypt data")
|
|
||||||
assert.NotNil(t, encrypted, "encrypted data is nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_SymmetricallyEncrypt_Bad(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
// Test with empty passphrase
|
|
||||||
_, err := s.SymmetricallyEncrypt([]byte(""), []byte("hello world"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_SymmetricallyDecrypt_Good(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
passphrase := []byte("hello world")
|
|
||||||
data := []byte("hello world")
|
|
||||||
encrypted, err := s.SymmetricallyEncrypt(passphrase, data)
|
|
||||||
require.NoError(t, err, "failed to encrypt data")
|
|
||||||
assert.NotNil(t, encrypted, "encrypted data is nil")
|
|
||||||
|
|
||||||
decrypted, err := s.SymmetricallyDecrypt(passphrase, encrypted)
|
|
||||||
require.NoError(t, err, "failed to decrypt data")
|
|
||||||
assert.Equal(t, data, decrypted, "decrypted data does not match original")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_SymmetricallyDecrypt_Bad(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
// Test with empty passphrase
|
|
||||||
_, err := s.SymmetricallyDecrypt([]byte(""), []byte("hello world"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test with wrong passphrase
|
|
||||||
passphrase := []byte("hello world")
|
|
||||||
data := []byte("hello world")
|
|
||||||
encrypted, err := s.SymmetricallyEncrypt(passphrase, data)
|
|
||||||
require.NoError(t, err, "failed to encrypt data")
|
|
||||||
|
|
||||||
_, err = s.SymmetricallyDecrypt([]byte("wrong passphrase"), encrypted)
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test with bad encrypted data
|
|
||||||
_, err = s.SymmetricallyDecrypt(passphrase, []byte("bad encrypted data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test with corrupt body
|
|
||||||
pub3, priv3, err := s.GenerateKeyPair("test3", "test3@test.com", "test3")
|
|
||||||
require.NoError(t, err)
|
|
||||||
encrypted3, err := s.Encrypt(pub3, []byte("hello world"))
|
|
||||||
require.NoError(t, err)
|
|
||||||
encrypted3[len(encrypted3)-1] ^= 0x01
|
|
||||||
_, err = s.Decrypt(priv3, encrypted3)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Encrypt_Bad(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
_, err := s.Encrypt([]byte("bad key"), []byte("hello world"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Decrypt_Good(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
pub, priv, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
||||||
require.NoError(t, err, "failed to generate key pair")
|
|
||||||
assert.NotNil(t, pub, "public key is nil")
|
|
||||||
assert.NotNil(t, priv, "private key is nil")
|
|
||||||
|
|
||||||
data := []byte("hello world")
|
|
||||||
encrypted, err := s.Encrypt(pub, data)
|
|
||||||
require.NoError(t, err, "failed to encrypt data")
|
|
||||||
assert.NotNil(t, encrypted, "encrypted data is nil")
|
|
||||||
|
|
||||||
decrypted, err := s.Decrypt(priv, encrypted)
|
|
||||||
require.NoError(t, err, "failed to decrypt data")
|
|
||||||
assert.Equal(t, data, decrypted, "decrypted data does not match original")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Decrypt_Bad(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
_, err := s.Decrypt([]byte("bad key"), []byte("hello world"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
pub, _, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
||||||
require.NoError(t, err)
|
|
||||||
_, priv2, err := s.GenerateKeyPair("test2", "test2@test.com", "test2")
|
|
||||||
require.NoError(t, err)
|
|
||||||
encrypted, err := s.Encrypt(pub, []byte("hello world"))
|
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = s.Decrypt(priv2, encrypted)
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
_, err = s.Decrypt(priv2, []byte("bad encrypted data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test with corrupt body
|
|
||||||
pub3, priv3, err := s.GenerateKeyPair("test3", "test3@test.com", "test3")
|
|
||||||
require.NoError(t, err)
|
|
||||||
encrypted3, err := s.Encrypt(pub3, []byte("hello world"))
|
|
||||||
require.NoError(t, err)
|
|
||||||
encrypted3[len(encrypted3)-1] ^= 0x01
|
|
||||||
_, err = s.Decrypt(priv3, encrypted3)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Sign_Good(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
_, priv, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
||||||
require.NoError(t, err, "failed to generate key pair")
|
|
||||||
assert.NotNil(t, priv, "private key is nil")
|
|
||||||
|
|
||||||
data := []byte("hello world")
|
|
||||||
signature, err := s.Sign(priv, data)
|
|
||||||
require.NoError(t, err, "failed to sign data")
|
|
||||||
assert.NotNil(t, signature, "signature is nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Sign_Bad(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
_, err := s.Sign([]byte("bad key"), []byte("hello world"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
// Test with public key (no private key)
|
|
||||||
pub, _, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = s.Sign(pub, []byte("hello world"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "private key not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Verify_Good(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
pub, priv, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
||||||
require.NoError(t, err, "failed to generate key pair")
|
|
||||||
assert.NotNil(t, pub, "public key is nil")
|
|
||||||
assert.NotNil(t, priv, "private key is nil")
|
|
||||||
|
|
||||||
data := []byte("hello world")
|
|
||||||
signature, err := s.Sign(priv, data)
|
|
||||||
require.NoError(t, err, "failed to sign data")
|
|
||||||
assert.NotNil(t, signature, "signature is nil")
|
|
||||||
|
|
||||||
err = s.Verify(pub, data, signature)
|
|
||||||
require.NoError(t, err, "failed to verify signature")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Verify_Bad(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
err := s.Verify([]byte("bad key"), []byte("hello world"), []byte("bad signature"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
_, priv, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
||||||
require.NoError(t, err)
|
|
||||||
pub2, _, err := s.GenerateKeyPair("test2", "test2@test.com", "test2")
|
|
||||||
require.NoError(t, err)
|
|
||||||
signature, err := s.Sign(priv, []byte("hello world"))
|
|
||||||
require.NoError(t, err)
|
|
||||||
err = s.Verify(pub2, []byte("hello world"), signature)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_SymmetricallyEncrypt_Good(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
passphrase := []byte("hello world")
|
|
||||||
data := []byte("hello world")
|
|
||||||
encrypted, err := s.SymmetricallyEncrypt(passphrase, data)
|
|
||||||
require.NoError(t, err, "failed to encrypt data")
|
|
||||||
assert.NotNil(t, encrypted, "encrypted data is nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mock testing infrastructure
|
|
||||||
|
|
||||||
type mockWriteCloser struct {
|
|
||||||
writeFunc func(p []byte) (n int, err error)
|
|
||||||
closeFunc func() error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockWriteCloser) Write(p []byte) (n int, err error) {
|
|
||||||
if m.writeFunc != nil {
|
|
||||||
return m.writeFunc(p)
|
|
||||||
}
|
|
||||||
return len(p), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockWriteCloser) Close() error {
|
|
||||||
if m.closeFunc != nil {
|
|
||||||
return m.closeFunc()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type mockReader struct {
|
|
||||||
readFunc func(p []byte) (n int, err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockReader) Read(p []byte) (n int, err error) {
|
|
||||||
if m.readFunc != nil {
|
|
||||||
return m.readFunc(p)
|
|
||||||
}
|
|
||||||
return 0, io.EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_GenerateKeyPair_MockErrors(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
origNewEntity := openpgpNewEntity
|
|
||||||
origArmorEncode := armorEncode
|
|
||||||
defer func() {
|
|
||||||
openpgpNewEntity = origNewEntity
|
|
||||||
armorEncode = origArmorEncode
|
|
||||||
}()
|
|
||||||
|
|
||||||
// 1. Mock NewEntity error
|
|
||||||
openpgpNewEntity = func(name, comment, email string, config *packet.Config) (*openpgp.Entity, error) {
|
|
||||||
return nil, errors.New("mock new entity error")
|
|
||||||
}
|
|
||||||
_, _, err := s.GenerateKeyPair("test", "test", "test")
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock new entity error")
|
|
||||||
openpgpNewEntity = origNewEntity // restore
|
|
||||||
|
|
||||||
// 2. Mock armorEncode error (public key)
|
|
||||||
armorEncode = func(out io.Writer, typeStr string, headers map[string]string) (io.WriteCloser, error) {
|
|
||||||
if typeStr == openpgp.PublicKeyType {
|
|
||||||
return nil, errors.New("mock armor pub error")
|
|
||||||
}
|
|
||||||
return origArmorEncode(out, typeStr, headers)
|
|
||||||
}
|
|
||||||
_, _, err = s.GenerateKeyPair("test", "test", "test")
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock armor pub error")
|
|
||||||
armorEncode = origArmorEncode // restore
|
|
||||||
|
|
||||||
// 3. Mock armorEncode error (private key)
|
|
||||||
armorEncode = func(out io.Writer, typeStr string, headers map[string]string) (io.WriteCloser, error) {
|
|
||||||
if typeStr == openpgp.PrivateKeyType {
|
|
||||||
return nil, errors.New("mock armor priv error")
|
|
||||||
}
|
|
||||||
return origArmorEncode(out, typeStr, headers)
|
|
||||||
}
|
|
||||||
_, _, err = s.GenerateKeyPair("test", "test", "test")
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock armor priv error")
|
|
||||||
armorEncode = origArmorEncode // restore
|
|
||||||
|
|
||||||
// 4. Mock Serialize error (via Write failure)
|
|
||||||
// We need armorEncode to return a writer that fails on Write
|
|
||||||
armorEncode = func(out io.Writer, typeStr string, headers map[string]string) (io.WriteCloser, error) {
|
|
||||||
if typeStr == openpgp.PublicKeyType {
|
|
||||||
return &mockWriteCloser{
|
|
||||||
writeFunc: func(p []byte) (n int, err error) {
|
|
||||||
return 0, errors.New("mock write pub error")
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
return origArmorEncode(out, typeStr, headers)
|
|
||||||
}
|
|
||||||
_, _, err = s.GenerateKeyPair("test", "test", "test")
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock write pub error")
|
|
||||||
armorEncode = origArmorEncode // restore
|
|
||||||
|
|
||||||
// 5. Mock SerializePrivate error (via Write failure)
|
|
||||||
armorEncode = func(out io.Writer, typeStr string, headers map[string]string) (io.WriteCloser, error) {
|
|
||||||
if typeStr == openpgp.PrivateKeyType {
|
|
||||||
return &mockWriteCloser{
|
|
||||||
writeFunc: func(p []byte) (n int, err error) {
|
|
||||||
return 0, errors.New("mock write priv error")
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
return origArmorEncode(out, typeStr, headers)
|
|
||||||
}
|
|
||||||
_, _, err = s.GenerateKeyPair("test", "test", "test")
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock write priv error")
|
|
||||||
armorEncode = origArmorEncode // restore
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func TestService_Encrypt_MockErrors(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
pub, _, err := s.GenerateKeyPair("test", "test", "test")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
origEncrypt := openpgpEncrypt
|
|
||||||
defer func() { openpgpEncrypt = origEncrypt }()
|
|
||||||
|
|
||||||
// 1. Mock Encrypt error
|
|
||||||
openpgpEncrypt = func(ciphertext io.Writer, to []*openpgp.Entity, signed *openpgp.Entity, hints *openpgp.FileHints, config *packet.Config) (io.WriteCloser, error) {
|
|
||||||
return nil, errors.New("mock encrypt error")
|
|
||||||
}
|
|
||||||
_, err = s.Encrypt(pub, []byte("data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock encrypt error")
|
|
||||||
|
|
||||||
// 2. Mock Write error
|
|
||||||
openpgpEncrypt = func(ciphertext io.Writer, to []*openpgp.Entity, signed *openpgp.Entity, hints *openpgp.FileHints, config *packet.Config) (io.WriteCloser, error) {
|
|
||||||
return &mockWriteCloser{
|
|
||||||
writeFunc: func(p []byte) (n int, err error) {
|
|
||||||
return 0, errors.New("mock write data error")
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
_, err = s.Encrypt(pub, []byte("data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock write data error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_Sign_MockErrors(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
_, priv, err := s.GenerateKeyPair("test", "test", "test")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
origSign := openpgpArmoredDetachSign
|
|
||||||
defer func() { openpgpArmoredDetachSign = origSign }()
|
|
||||||
|
|
||||||
// Mock Sign error
|
|
||||||
openpgpArmoredDetachSign = func(w io.Writer, signer *openpgp.Entity, message io.Reader, config *packet.Config) error {
|
|
||||||
return errors.New("mock sign error")
|
|
||||||
}
|
|
||||||
_, err = s.Sign(priv, []byte("data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock sign error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_SymmetricallyEncrypt_MockErrors(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
|
|
||||||
origSymEncrypt := openpgpSymmetricallyEncrypt
|
|
||||||
defer func() { openpgpSymmetricallyEncrypt = origSymEncrypt }()
|
|
||||||
|
|
||||||
// 1. Mock Sym Encrypt error
|
|
||||||
openpgpSymmetricallyEncrypt = func(ciphertext io.Writer, passphrase []byte, hints *openpgp.FileHints, config *packet.Config) (io.WriteCloser, error) {
|
|
||||||
return nil, errors.New("mock sym encrypt error")
|
|
||||||
}
|
|
||||||
_, err := s.SymmetricallyEncrypt([]byte("pass"), []byte("data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock sym encrypt error")
|
|
||||||
|
|
||||||
// 2. Mock Write error
|
|
||||||
openpgpSymmetricallyEncrypt = func(ciphertext io.Writer, passphrase []byte, hints *openpgp.FileHints, config *packet.Config) (io.WriteCloser, error) {
|
|
||||||
return &mockWriteCloser{
|
|
||||||
writeFunc: func(p []byte) (n int, err error) {
|
|
||||||
return 0, errors.New("mock sym write error")
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
_, err = s.SymmetricallyEncrypt([]byte("pass"), []byte("data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock sym write error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestService_SymmetricallyDecrypt_MockErrors(t *testing.T) {
|
|
||||||
s := NewService()
|
|
||||||
pass := []byte("pass")
|
|
||||||
|
|
||||||
origReadMessage := openpgpReadMessage
|
|
||||||
defer func() { openpgpReadMessage = origReadMessage }()
|
|
||||||
|
|
||||||
// Mock ReadMessage error
|
|
||||||
openpgpReadMessage = func(r io.Reader, keyring openpgp.KeyRing, prompt openpgp.PromptFunction, config *packet.Config) (*openpgp.MessageDetails, error) {
|
|
||||||
return nil, errors.New("mock read message error")
|
|
||||||
}
|
|
||||||
_, err := s.SymmetricallyDecrypt(pass, []byte("data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock read message error")
|
|
||||||
|
|
||||||
// Mock ReadAll error (via ReadMessage returning bad body)
|
|
||||||
openpgpReadMessage = func(r io.Reader, keyring openpgp.KeyRing, prompt openpgp.PromptFunction, config *packet.Config) (*openpgp.MessageDetails, error) {
|
|
||||||
// We need to return a message with UnverifiedBody that fails on Read
|
|
||||||
return &openpgp.MessageDetails{
|
|
||||||
UnverifiedBody: &mockReader{
|
|
||||||
readFunc: func(p []byte) (n int, err error) {
|
|
||||||
return 0, errors.New("mock read body error")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
_, err = s.SymmetricallyDecrypt(pass, []byte("data"))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "mock read body error")
|
|
||||||
}
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
package rsa
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/rand"
|
|
||||||
"crypto/rsa"
|
|
||||||
"crypto/sha256"
|
|
||||||
"crypto/x509"
|
|
||||||
"encoding/pem"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Service provides RSA functionality.
|
|
||||||
type Service struct{}
|
|
||||||
|
|
||||||
// NewService creates and returns a new Service instance for performing RSA-related operations.
|
|
||||||
func NewService() *Service {
|
|
||||||
return &Service{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateKeyPair creates a new RSA key pair.
|
|
||||||
func (s *Service) GenerateKeyPair(bits int) (publicKey, privateKey []byte, err error) {
|
|
||||||
if bits < 2048 {
|
|
||||||
return nil, nil, fmt.Errorf("rsa: key size too small: %d (minimum 2048)", bits)
|
|
||||||
}
|
|
||||||
privKey, err := rsa.GenerateKey(rand.Reader, bits)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("failed to generate private key: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
privKeyBytes := x509.MarshalPKCS1PrivateKey(privKey)
|
|
||||||
privKeyPEM := pem.EncodeToMemory(&pem.Block{
|
|
||||||
Type: "RSA PRIVATE KEY",
|
|
||||||
Bytes: privKeyBytes,
|
|
||||||
})
|
|
||||||
|
|
||||||
pubKeyBytes, err := x509.MarshalPKIXPublicKey(&privKey.PublicKey)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("failed to marshal public key: %w", err)
|
|
||||||
}
|
|
||||||
pubKeyPEM := pem.EncodeToMemory(&pem.Block{
|
|
||||||
Type: "PUBLIC KEY",
|
|
||||||
Bytes: pubKeyBytes,
|
|
||||||
})
|
|
||||||
|
|
||||||
return pubKeyPEM, privKeyPEM, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encrypt encrypts data with a public key.
|
|
||||||
func (s *Service) Encrypt(publicKey, data, label []byte) ([]byte, error) {
|
|
||||||
block, _ := pem.Decode(publicKey)
|
|
||||||
if block == nil {
|
|
||||||
return nil, fmt.Errorf("failed to decode public key")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to parse public key: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rsaPub, ok := pub.(*rsa.PublicKey)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("not an RSA public key")
|
|
||||||
}
|
|
||||||
|
|
||||||
ciphertext, err := rsa.EncryptOAEP(sha256.New(), rand.Reader, rsaPub, data, label)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to encrypt data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ciphertext, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decrypt decrypts data with a private key.
|
|
||||||
func (s *Service) Decrypt(privateKey, ciphertext, label []byte) ([]byte, error) {
|
|
||||||
block, _ := pem.Decode(privateKey)
|
|
||||||
if block == nil {
|
|
||||||
return nil, fmt.Errorf("failed to decode private key")
|
|
||||||
}
|
|
||||||
|
|
||||||
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to parse private key: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
plaintext, err := rsa.DecryptOAEP(sha256.New(), rand.Reader, priv, ciphertext, label)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to decrypt data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return plaintext, nil
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue