Skip to content

Commit c715048

Browse files
committed
fast-ssdeep initial release
0 parents  commit c715048

15 files changed

+1410
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/dependabot.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"

.github/workflows/build.yml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: "Build (w/ tests)"
2+
3+
on:
4+
push:
5+
release:
6+
types: [published]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: ['18.x', '20.x']
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
submodules: true
21+
22+
- name: Setup Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
registry-url: 'https://registry.npmjs.org'
27+
28+
- name: Install pnpm
29+
uses: pnpm/action-setup@v4
30+
with:
31+
version: latest
32+
33+
- name: Get pnpm store directory
34+
id: pnpm-cache
35+
run: |
36+
echo "STORE_PATH=$(pnpm store path)" >> "$GITHUB_OUTPUT"
37+
38+
- uses: actions/cache@v4
39+
name: Setup pnpm cache
40+
with:
41+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
42+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
43+
restore-keys: |
44+
${{ runner.os }}-pnpm-store-
45+
46+
- name: Install dependencies
47+
run: pnpm install --frozen-lockfile
48+
49+
- name: Run tests
50+
run: pnpm run test
51+
52+
release:
53+
runs-on: ubuntu-latest
54+
if: github.event_name == 'release'
55+
56+
permissions:
57+
id-token: write #npm provenance
58+
environment:
59+
name: npm
60+
url: https://www.npmjs.org/package/fast-ssdeep
61+
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
with:
66+
submodules: true
67+
68+
- name: Setup Node.js 20
69+
uses: actions/setup-node@v4
70+
with:
71+
node-version: 20
72+
registry-url: 'https://registry.npmjs.org'
73+
74+
- name: Install pnpm
75+
uses: pnpm/action-setup@v3
76+
with:
77+
version: latest
78+
79+
- name: Get pnpm store directory
80+
id: pnpm-cache
81+
run: |
82+
echo "STORE_PATH=$(pnpm store path)" >> "$GITHUB_OUTPUT"
83+
84+
- uses: actions/cache@v4
85+
name: Setup pnpm cache
86+
with:
87+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
88+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
89+
restore-keys: |
90+
${{ runner.os }}-pnpm-store-
91+
92+
- name: Publish to npmjs
93+
run: pnpm publish --provenance --no-git-checks --access public
94+
env:
95+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/
40+
build/Release
41+
42+
# Dependency directories
43+
node_modules/
44+
jspm_packages/
45+
46+
# Snowpack dependency directory (https://snowpack.dev/)
47+
web_modules/
48+
49+
# TypeScript cache
50+
*.tsbuildinfo
51+
52+
# Optional npm cache directory
53+
.npm
54+
55+
# Optional eslint cache
56+
.eslintcache
57+
58+
# Optional stylelint cache
59+
.stylelintcache
60+
61+
# Microbundle cache
62+
.rpt2_cache/
63+
.rts2_cache_cjs/
64+
.rts2_cache_es/
65+
.rts2_cache_umd/
66+
67+
# Optional REPL history
68+
.node_repl_history
69+
70+
# Output of 'npm pack'
71+
*.tgz
72+
73+
# Yarn Integrity file
74+
.yarn-integrity
75+
76+
# dotenv environment variable files
77+
.env
78+
.env.development.local
79+
.env.test.local
80+
.env.production.local
81+
.env.local
82+
83+
# parcel-bundler cache (https://parceljs.org/)
84+
.cache
85+
.parcel-cache
86+
87+
# Next.js build output
88+
.next
89+
out
90+
91+
# Nuxt.js build / generate output
92+
.nuxt
93+
dist
94+
95+
# Gatsby files
96+
.cache/
97+
# Comment in the public line in if your project uses Gatsby and not Next.js
98+
# https://nextjs.org/blog/next-9-1#public-directory-support
99+
# public
100+
101+
# vuepress build output
102+
.vuepress/dist
103+
104+
# vuepress v2.x temp and cache directory
105+
.temp
106+
.cache
107+
108+
# Docusaurus cache and generated files
109+
.docusaurus
110+
111+
# Serverless directories
112+
.serverless/
113+
114+
# FuseBox cache
115+
.fusebox/
116+
117+
# DynamoDB Local files
118+
.dynamodb/
119+
120+
# TernJS port file
121+
.tern-port
122+
123+
# Stores VSCode versions used for testing VSCode extensions
124+
.vscode-test
125+
126+
# yarn v2
127+
.yarn/cache
128+
.yarn/unplugged
129+
.yarn/build-state.yml
130+
.yarn/install-state.gz
131+
.pnp.*
132+
133+
# Ignore VSCode settings
134+
.vscode

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "ssdeep"]
2+
path = ssdeep
3+
url = https://github.com/ssdeep-project/ssdeep

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 memcorrupt
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# fast-ssdeep
2+
3+
[![Version](https://img.shields.io/npm/v/fast-ssdeep.svg)](https://www.npmjs.org/package/fast-ssdeep)
4+
[![Downloads](https://img.shields.io/npm/dm/fast-ssdeep.svg)](https://www.npmjs.com/package/fast-ssdeep)
5+
[![Build Status](https://github.com/memcorrupt/fast-ssdeep/actions/workflows/release.yml/badge.svg)](https://github.com/memcorrupt/fast-ssdeep/actions/workflows/build.yml)
6+
[![License](https://img.shields.io/github/license/memcorrupt/fast-ssdeep)](LICENSE)
7+
8+
Node.js binding for the ssdeep CTPH library.
9+
10+
[ssdeep project website](https://ssdeep-project.github.io/ssdeep/index.html)
11+
12+
# Installation
13+
14+
Install the [fast-ssdeep](https://npmjs.org/package/fast-ssdeep) package from the NPM registry using your package manager of choice.
15+
16+
Example:
17+
18+
```
19+
npm install fast-ssdeep
20+
# or
21+
yarn add fast-ssdeep
22+
# or
23+
pnpm install fast-ssdeep
24+
```
25+
26+
# Documentation
27+
28+
### `ssdeep.hash(contents: string|Buffer): Promise<string>`
29+
30+
Asynchronously calculate an ssdeep hash based on the `contents` argument, which can be a string or Buffer.
31+
32+
### `ssdeep.hashSync(contents: string|Buffer): string`
33+
34+
Synchronously calculate an ssdeep hash based on the `contents` argument, which can be a string or Buffer.
35+
36+
### `ssdeep.compare(hash1: string, hash2: string): Promise<number>`
37+
38+
Asynchronously compare two ssdeep hashes to generate a similarity score. Both hashes must be passed as strings, and a similarity between 0-100 will be returned.
39+
40+
### `ssdeep.compareSync(hash1: string, hash2: string): number`
41+
42+
Synchronously compare two ssdeep hashes to generate a similarity score. Both hashes must be passed as strings, and a similarity between 0-100 will be returned.

binding.gyp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'fast-ssdeep',
5+
'sources': [
6+
'src/ssdeep_node.c',
7+
'src/polyfill.c',
8+
9+
'ssdeep/fuzzy.c',
10+
'ssdeep/edit_dist.c'
11+
]
12+
}
13+
]
14+
}

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const bindings = require('bindings')('fast-ssdeep.node');
2+
3+
delete bindings.path; //bindings lib adds this
4+
5+
module.exports = bindings;

package.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "fast-ssdeep",
3+
"version": "1.0.0",
4+
"description": "Node.js binding for the ssdeep CTPH library",
5+
"main": "index.js",
6+
"engines": {
7+
"node": ">= 10.0.0"
8+
},
9+
"scripts": {
10+
"test": "mocha",
11+
"build": "node-gyp build",
12+
"install": "node-gyp rebuild"
13+
},
14+
"files": [
15+
"src",
16+
"test",
17+
18+
"ssdeep/fuzzy.c",
19+
"ssdeep/edit_dist.c",
20+
"ssdeep/fuzzy.h",
21+
"ssdeep/edit_dist.h",
22+
"ssdeep/sum_table.h",
23+
24+
"index.js",
25+
"binding.gyp"
26+
],
27+
"repository": {
28+
"type": "git",
29+
"url": "git+https://github.com/memcorrupt/fast-ssdeep.git"
30+
},
31+
"keywords": [
32+
"ssdeep",
33+
"ctph",
34+
"hashing",
35+
"fuzzy"
36+
],
37+
"author": "memcorrupt <[email protected]>",
38+
"license": "MIT",
39+
"bugs": {
40+
"url": "https://github.com/memcorrupt/fast-ssdeep/issues"
41+
},
42+
"homepage": "https://github.com/memcorrupt/fast-ssdeep#readme",
43+
"devDependencies": {
44+
"mocha": "^10.7.3"
45+
},
46+
"dependencies": {
47+
"bindings": "^1.5.0"
48+
}
49+
}

0 commit comments

Comments
 (0)