sign.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var Base, BufferInStream, Command, E, TrackSubSubCommand, User, add_option_dict, gpg, iced, keypull, log, make_esc, __iced_k, __iced_k_noop,
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  6. iced = require('iced-runtime').iced;
  7. __iced_k = __iced_k_noop = function() {};
  8. Base = require('./base').Base;
  9. log = require('../log');
  10. add_option_dict = require('./argparse').add_option_dict;
  11. E = require('../err').E;
  12. TrackSubSubCommand = require('../tracksubsub').TrackSubSubCommand;
  13. BufferInStream = require('iced-spawn').BufferInStream;
  14. gpg = require('../gpg').gpg;
  15. make_esc = require('iced-error').make_esc;
  16. User = require('../user').User;
  17. keypull = require('../keypull').keypull;
  18. exports.Command = Command = (function(_super) {
  19. __extends(Command, _super);
  20. function Command() {
  21. return Command.__super__.constructor.apply(this, arguments);
  22. }
  23. Command.prototype.OPTS = {
  24. m: {
  25. alias: "message",
  26. help: "provide the message on the command line"
  27. },
  28. b: {
  29. alias: 'binary',
  30. action: "storeTrue",
  31. help: "output in binary (rather than ASCII/armored)"
  32. },
  33. 'clearsign': {
  34. action: 'storeTrue',
  35. help: "make a clear signature"
  36. },
  37. 'detach-sign': {
  38. action: 'storeTrue',
  39. help: "make a detached signature"
  40. },
  41. o: {
  42. alias: 'output',
  43. help: 'specify an output file'
  44. }
  45. };
  46. Command.prototype.is_batch = function() {
  47. return !(this.argv.message != null) && !(this.argv.file != null);
  48. };
  49. Command.prototype.set_argv = function(a) {
  50. if (a.clearsign && a.detach_sign) {
  51. return new E.ArgsError("Can only handle one of --clearsign and --detach-sign");
  52. } else {
  53. return Command.__super__.set_argv.call(this, a);
  54. }
  55. };
  56. Command.prototype.add_subcommand_parser = function(scp) {
  57. var name, opts, sub;
  58. opts = {
  59. aliases: ["sig"],
  60. help: "sign a message"
  61. };
  62. name = "sign";
  63. sub = scp.addParser(name, opts);
  64. add_option_dict(sub, this.OPTS);
  65. sub.addArgument(["file"], {
  66. nargs: '?'
  67. });
  68. return opts.aliases.concat([name]);
  69. };
  70. Command.prototype.do_sign = function(cb) {
  71. var args, err, gargs, o, out, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  72. __iced_k = __iced_k_noop;
  73. ___iced_passed_deferral = iced.findDeferral(arguments);
  74. args = ["--sign", "-u", this.me.fingerprint(true)];
  75. gargs = {
  76. args: args
  77. };
  78. if (!this.argv.binary) {
  79. args.push("-a");
  80. }
  81. if (this.argv.clearsign) {
  82. args.push("--clearsign");
  83. }
  84. if (this.argv.detach_sign) {
  85. args.push("--detach-sign");
  86. }
  87. if ((o = this.argv.output) != null) {
  88. args.push("--output", o);
  89. }
  90. if (this.argv.message) {
  91. gargs.stdin = new BufferInStream(this.argv.message);
  92. } else if (this.argv.file != null) {
  93. args.push(this.argv.file);
  94. } else {
  95. gargs.stdin = process.stdin;
  96. }
  97. (function(_this) {
  98. return (function(__iced_k) {
  99. __iced_deferrals = new iced.Deferrals(__iced_k, {
  100. parent: ___iced_passed_deferral,
  101. filename: "/Users/max/src/keybase/node-client/src/command/sign.iced",
  102. funcname: "Command.do_sign"
  103. });
  104. gpg(gargs, __iced_deferrals.defer({
  105. assign_fn: (function() {
  106. return function() {
  107. err = arguments[0];
  108. return out = arguments[1];
  109. };
  110. })(),
  111. lineno: 74
  112. }));
  113. __iced_deferrals._fulfill();
  114. });
  115. })(this)((function(_this) {
  116. return function() {
  117. if (!_this.argv.output) {
  118. log.console.log(out.toString(_this.argv.binary ? 'utf8' : 'binary'));
  119. }
  120. return cb(err);
  121. };
  122. })(this));
  123. };
  124. Command.prototype.load_me = function(cb) {
  125. var err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  126. __iced_k = __iced_k_noop;
  127. ___iced_passed_deferral = iced.findDeferral(arguments);
  128. (function(_this) {
  129. return (function(__iced_k) {
  130. __iced_deferrals = new iced.Deferrals(__iced_k, {
  131. parent: ___iced_passed_deferral,
  132. filename: "/Users/max/src/keybase/node-client/src/command/sign.iced",
  133. funcname: "Command.load_me"
  134. });
  135. User.load_me({
  136. secret: true
  137. }, __iced_deferrals.defer({
  138. assign_fn: (function(__slot_1) {
  139. return function() {
  140. err = arguments[0];
  141. return __slot_1.me = arguments[1];
  142. };
  143. })(_this),
  144. lineno: 82
  145. }));
  146. __iced_deferrals._fulfill();
  147. });
  148. })(this)((function(_this) {
  149. return function() {
  150. return cb(err);
  151. };
  152. })(this));
  153. };
  154. Command.prototype.run = function(cb) {
  155. var esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  156. __iced_k = __iced_k_noop;
  157. ___iced_passed_deferral = iced.findDeferral(arguments);
  158. esc = make_esc(cb, "Command::run");
  159. log.debug("+ Command::run");
  160. (function(_this) {
  161. return (function(__iced_k) {
  162. __iced_deferrals = new iced.Deferrals(__iced_k, {
  163. parent: ___iced_passed_deferral,
  164. filename: "/Users/max/src/keybase/node-client/src/command/sign.iced",
  165. funcname: "Command.run"
  166. });
  167. keypull({
  168. stdin_blocked: _this.is_batch(),
  169. need_secret: true
  170. }, esc(__iced_deferrals.defer({
  171. lineno: 90
  172. })));
  173. __iced_deferrals._fulfill();
  174. });
  175. })(this)((function(_this) {
  176. return function() {
  177. (function(__iced_k) {
  178. __iced_deferrals = new iced.Deferrals(__iced_k, {
  179. parent: ___iced_passed_deferral,
  180. filename: "/Users/max/src/keybase/node-client/src/command/sign.iced",
  181. funcname: "Command.run"
  182. });
  183. _this.load_me(esc(__iced_deferrals.defer({
  184. lineno: 91
  185. })));
  186. __iced_deferrals._fulfill();
  187. })(function() {
  188. (function(__iced_k) {
  189. __iced_deferrals = new iced.Deferrals(__iced_k, {
  190. parent: ___iced_passed_deferral,
  191. filename: "/Users/max/src/keybase/node-client/src/command/sign.iced",
  192. funcname: "Command.run"
  193. });
  194. _this.do_sign(esc(__iced_deferrals.defer({
  195. lineno: 92
  196. })));
  197. __iced_deferrals._fulfill();
  198. })(function() {
  199. log.debug("- Command::run");
  200. return cb(null);
  201. });
  202. });
  203. };
  204. })(this));
  205. };
  206. return Command;
  207. })(Base);
  208. }).call(this);