UNPKG

keybase-proofs

Version:

Publicly-verifiable proofs of identity

88 lines (78 loc) 2.16 kB
// Generated by IcedCoffeeScript 108.0.11 (function() { var Finder, base64_extract, bufeq_fast; bufeq_fast = require('pgp-utils').util.bufeq_fast; exports.base64_extract = base64_extract = function(text) { var b64x, curr, hit_b64, hit_non_b64, out, state, tok, tokens, _i, _len; b64x = /^[a-zA-Z0-9/+_-]+(=*)$/; tokens = text.split(/\s+/); state = 0; out = []; curr = []; hit_non_b64 = function() { if (curr.length) { out.push(curr.join('')); return curr = []; } }; hit_b64 = function(tok) { return curr.push(tok); }; for (_i = 0, _len = tokens.length; _i < _len; _i++) { tok = tokens[_i]; if (tok.match(b64x)) { hit_b64(tok); } else { hit_non_b64(); } } hit_non_b64(); return out; }; Finder = (function() { function Finder(corpus) { this.rxx = new RegExp('^\\s*(([a-zA-Z0-9/+_-]+)(={0,3}))\\s*$'); this.lines = corpus.split(/\r*\n/); } Finder.prototype.find_one_block = function(start) { var found, i, line, ln_out, m, parts, _i, _len, _ref; found = false; ln_out = start; parts = []; _ref = this.lines.slice(start); for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { line = _ref[i]; ln_out++; if ((m = line.match(this.rxx)) != null) { found = true; parts.push(m[1]); if (m[3].length > 0) { ln_out++; break; } } else if (found) { break; } } return [parts.join(""), ln_out]; }; Finder.prototype.find = function(needle) { var buf, i, msg, _ref; i = 0; while (i < this.lines.length) { _ref = this.find_one_block(i), msg = _ref[0], i = _ref[1]; if (msg.length) { buf = Buffer.from(msg, 'base64'); if (bufeq_fast(buf, needle)) { return true; } } } return false; }; return Finder; })(); exports.b64find = function(haystack, needle) { return (new Finder(haystack)).find(needle); }; }).call(this);