gpg.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var E, GPG, StatusParser, env, iced, log, util, __iced_k, __iced_k_noop;
  4. iced = require('iced-runtime').iced;
  5. __iced_k = __iced_k_noop = function() {};
  6. GPG = require('gpg-wrapper').GPG;
  7. env = require('./env').env;
  8. log = require('./log');
  9. util = require('util');
  10. E = require('./err').E;
  11. exports.gpg = function(inargs, cb) {
  12. var err, gpg, out, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  13. __iced_k = __iced_k_noop;
  14. ___iced_passed_deferral = iced.findDeferral(arguments);
  15. log.debug("| Call to gpg: " + (util.inspect(inargs)));
  16. if (inargs.quiet && env().get_debug()) {
  17. inargs.quiet = false;
  18. }
  19. gpg = new GPG;
  20. (function(_this) {
  21. return (function(__iced_k) {
  22. __iced_deferrals = new iced.Deferrals(__iced_k, {
  23. parent: ___iced_passed_deferral,
  24. filename: "/Users/max/src/keybase/node-client/src/gpg.iced",
  25. funcname: "gpg"
  26. });
  27. gpg.run(inargs, __iced_deferrals.defer({
  28. assign_fn: (function() {
  29. return function() {
  30. err = arguments[0];
  31. return out = arguments[1];
  32. };
  33. })(),
  34. lineno: 13
  35. }));
  36. __iced_deferrals._fulfill();
  37. });
  38. })(this)((function(_this) {
  39. return function() {
  40. return cb(err, out);
  41. };
  42. })(this));
  43. };
  44. exports.StatusParser = StatusParser = (function() {
  45. function StatusParser() {
  46. this._all = [];
  47. this._table = [];
  48. }
  49. StatusParser.prototype.parse = function(_arg) {
  50. var buf, line, lines, words, _i, _len;
  51. buf = _arg.buf;
  52. lines = buf.toString('utf8').split(/\r?\n/);
  53. for (_i = 0, _len = lines.length; _i < _len; _i++) {
  54. line = lines[_i];
  55. words = line.split(/\s+/);
  56. if (words[0] === '[GNUPG:]') {
  57. this._all.push(words.slice(1));
  58. this._table[words[1]] = words.slice(2);
  59. }
  60. }
  61. return this;
  62. };
  63. StatusParser.prototype.lookup = function(key) {
  64. return this._table[key];
  65. };
  66. return StatusParser;
  67. })();
  68. exports.parse_signature = function(buf) {
  69. var d, err, key, status_parser, timestamp, validsig;
  70. status_parser = (new StatusParser()).parse({
  71. buf: buf
  72. });
  73. err = key = timestamp = null;
  74. d = null;
  75. if ((validsig = status_parser.lookup("VALIDSIG")) == null) {
  76. err = new E.NotFoundError("no valid signature found");
  77. } else if (validsig.length < 9 || isNaN(d = parseInt(validsig[2]))) {
  78. err = new E.VerifyError("didn't find a valid signature");
  79. } else {
  80. if (validsig.length === 10) {
  81. key = {
  82. primary: validsig[9],
  83. subkey: validsig[0]
  84. };
  85. } else {
  86. key = {
  87. primary: validsig[0]
  88. };
  89. }
  90. timestamp = new Date(d * 1000);
  91. }
  92. return [err, key, timestamp];
  93. };
  94. }).call(this);