<commit_before>#!/usr/bin/env node

var jwcrypto = require("../index");

var cert_raw = process.argv[2];
var pk_raw = process.argv[3];

var cert = jwcrypto.extractComponents(cert_raw);
console.log("issuer: " + cert.payload.iss);
console.log("full payload: " + JSON.stringify(cert.payload));
console.log("principal:" + JSON.stringify(cert.payload.principal));
console.log("key:" + cert.payload['public-key'].serialize());
console.log("expiration:" + cert.payload.exp);

var pk = jwcrypto.loadPublicKey(pk_raw);

console.log("verifying the raw signature - no cert specific verification");

jwcrypto.verify(cert, pk, function(err, payload) {
  if (err) {
    console.log("doesn't work");
    console.log(err);
  } else{
    console.log("works");
  }
});<commit_msg>Fixing check-cert algorithms, adding CLI arguments support<commit_after>#!/usr/bin/env node

var
fs = require('fs'),
jwcrypto = require("../index");

// Side effects Issue #24
require("../lib/algs/ds");
require("../lib/algs/rs");

var args = require('optimist')
.usage('Check certificate\nUsage: $0')
.alias('p', 'public')
.describe('p', 'public key to sign')
.demand('p')
.alias('h', 'help')
.describe('h', 'display this usage message')
.alias('c', 'certificate')
.describe('c', 'A certificate which you want to examine.')
.demand('c')
.alias('d', 'debug')
.describe('d', 'Debug mode, useful for development of this tool')
.boolean('d')
.default('d', false);

var argv = args.argv;

var debug = argv.d;

if (debug) console.log('Reading cert file=', argv.c);
var cert_raw = fs.readFileSync(argv.c).toString('utf8');

var cert = jwcrypto.extractComponents(cert_raw);

console.log("issuer: " + cert.payload.iss);
console.log("full payload: " + JSON.stringify(cert.payload));
console.log("principal:" + JSON.stringify(cert.payload.principal));
console.log("key:" + JSON.stringify(cert.payload['public-key'], null, 4));
console.log("expiration:" + cert.payload.exp);

if (debug) console.log('Reading public file=', argv.p);
var pk_raw = fs.readFileSync(argv.p).toString('utf8');


var pk = jwcrypto.loadPublicKey(pk_raw);
if (debug) console.log(JSON.stringify(JSON.parse(pk.serialize()), null, 4));

console.log("verifying the raw signature - no cert specific verification");

jwcrypto.verify(cert, pk, function(err, payload) {
  if (err) {
    console.log("doesn't work");
    console.log(err);
  } else{
    console.log("works");
  }
});
{'fraction_non_alphanumeric': 0.1964956195244055, 'fraction_numerical': 0.0037546933667083854, 'mean_word_length': 5.277486910994765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2709455', 'n_tokens_mistral': 826, 'n_tokens_neox': 806, 'n_words': 179}