Skip to content
/ ncda Public

A Rust implementation of the NCDA (Noid Check Digit Algorithm) checking algorithm

License

Notifications You must be signed in to change notification settings

eonm-pro/ncda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NCDA (Noid Check Digit Algorithm)

A Rust implementation of the NCDA checking algorithm

Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept. License: MIT contributions welcome

NCDA in brief

NCDA (Noid Check Digit Algorithm) is an algorithm used to compute or validate NOID checksum char.

NCDA works well with identifiers such as ARKs. It can be used to assert that an ID doesn't contains transcription error.

NCDA is a part of the NOID project which was developed by John A. Kunze (@jkunze).

Motivation

This project is primarily a learning project. It has been inspired by the ark-tools project made by Bertrand Carron (@BertrandCaron).

This project is an attempt to build a full featured Rust app and lib from A to Z with few goals in mind:

  • Learn basic concepts of WebAssembly 🕸
  • Learn how to build python native modules with Rust and Pyo3 🐍
  • Learn how to build Web Services with Rocket.rs 🚀
  • Lean how to build GUI app with Tauri ⛩️
  • Keep learning things about Rust optimization and error handling 🦀
  • Learn basic concepts of OpenApi

This project tries to produce real outcomes such as :

  • A CLI
  • A GUI
  • A Web Service
  • A Rust library
  • A Nodejs library
  • A Python library

This implementation of NCDA provides bindings with :

  • Nodejs
  • Python

If this project reachs a stable state I will consider adding the ncda lib to crates.io, npm and pipy.

CLI

ncda 0.1.0
Mathis EON <[email protected]>
Checks and computes the checksum char of a Noid with the NCDA (Noid Check Digit Algorithm) algorithm

USAGE:
    ncda [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    check       Checks NOIDs
    checksum    Computes the checksum char of NOIDs
    help        Prints this message or the help of the given subcommand(s)
    ws          Starts the NCDA Web Service

Example : checking a list of NOIDs stored in a file

ncda check -i my_file.txt -o output.txt

Web Service

The Web Service can be launched from the CLI :

ncda ws --port 8080

The Web Service expose two functions check and checksum. Each function takes a list of comma separated NOIDs as parameter:

Build

Rust

This section explains how to use the NCDA crate inside your Rust project.

You can try this example with : cargo run --example basic

1- Create a new Rust project with cargo :

cargo init ncda-checking
cd ncda-checking

1- Add the following code to Cargo.toml :

[dependencies]
ncda = {git = "https://github.com/eonm-abes/ncda", branch="main"}

2- Add the following code to src/main.rs :

use ncda;

fn main() -> Result<(), ncda::NcdaError> {
    let unqualified_id = "cb32752361";
    println!("The checksum char of {} is : {:?}", unqualified_id, ncda::checksum(unqualified_id)?);
    
    let qualified_id = "cb32752361d";
    println!("{} is valid : {:?}", qualified_id, ncda::check(qualified_id).is_ok());

    Ok(())
}

3- Run your app :

cargo run

Nodejs

This section explains how to compile the NCDA library into a Nodejs module and how to use it inside your Nodejs app.

1- Compile the ncda library to Nodejs with wasm-pack :

wasm-pack build --release --target nodejs

2- Create a basic Nodejs project :

mkdir Nodejs && cd Nodejs
npm init -y     
npm i -D ../pkg
touch index.js

3- Add the following code to index.js :

const ncda = require("ncda");

let checksum_char = ncda.checksum('cb32752361');
let checking_result = ncda.check('cb32752361d');

console.log(`checksum char : ${checksum_char}`);
console.log(`cheking result for cb32752361d : ${checking_result}`);

4- Run your app :

node index.js

Python

This section explains how to compile the NCDA library into a Python native module and how to use it inside your Python app.

1- Build the library with cargo :

cargo build --release --lib

2- Rename the library file :

mv target/release/libncda.so target/release/ncda.so

3- Import and use the library from Python :

The ncda.so file must be in the same directory as your app

import ncda

nda.check("cb32752361d")
nda.checksum("cb32752361")

Benchmark

Like any benchmark you might get slightly different results on your system. The following results are provided solely for information purposes.

Measure ID length Result Tool
ncda::check 11 23 ns/iter (+/- 3) cargo bench
ncda::checksum 10 26 ns/iter (+/- 0) cargo bench
Total memory consumption 11 72.7 ko heaptrack

Other implementations and related projects (not limited)

References

About

A Rust implementation of the NCDA (Noid Check Digit Algorithm) checking algorithm

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages