encrypt.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var Base, BufferInStream, Command, E, TrackSubSubCommand, User, add_option_dict, dict_union, env, iced, log, make_esc, master_ring, __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. master_ring = require('../keyring').master_ring;
  15. make_esc = require('iced-error').make_esc;
  16. dict_union = require('../util').dict_union;
  17. User = require('../user').User;
  18. env = require('../env').env;
  19. exports.Command = Command = (function(_super) {
  20. __extends(Command, _super);
  21. function Command() {
  22. return Command.__super__.constructor.apply(this, arguments);
  23. }
  24. Command.prototype.OPTS = dict_union(TrackSubSubCommand.OPTS, {
  25. s: {
  26. alias: "sign",
  27. action: "storeTrue",
  28. help: "sign in addition to encrypting"
  29. },
  30. m: {
  31. alias: "message",
  32. help: "provide the message on the command line"
  33. },
  34. b: {
  35. alias: 'binary',
  36. action: "storeTrue",
  37. help: "output in binary (rather than ASCII/armored)"
  38. },
  39. o: {
  40. alias: 'output',
  41. help: 'the output file to write the encryption to'
  42. }
  43. });
  44. Command.prototype.add_subcommand_parser = function(scp) {
  45. var name, opts, sub;
  46. opts = {
  47. aliases: ["enc"],
  48. help: "encrypt a message and output to stdout or a file"
  49. };
  50. name = "encrypt";
  51. sub = scp.addParser(name, opts);
  52. add_option_dict(sub, this.OPTS);
  53. sub.addArgument(["them"], {
  54. nargs: 1,
  55. help: "the username of the receiver"
  56. });
  57. sub.addArgument(["file"], {
  58. nargs: '?',
  59. help: "the file to be encrypted"
  60. });
  61. return opts.aliases.concat([name]);
  62. };
  63. Command.prototype.do_encrypt = function(cb) {
  64. var args, err, gargs, key, o, out, sign_key, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
  65. __iced_k = __iced_k_noop;
  66. ___iced_passed_deferral = iced.findDeferral(arguments);
  67. args = ["--encrypt", "--trust-mode", "always"];
  68. _ref = this.them.gpg_keys;
  69. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  70. key = _ref[_i];
  71. args = args.concat("-r", key.fingerprint().toString('hex'));
  72. }
  73. if (this.argv.sign) {
  74. sign_key = this.is_self ? this.them : this.tssc.me;
  75. args.push("--sign", "-u", sign_key.fingerprint(true));
  76. }
  77. gargs = {
  78. args: args
  79. };
  80. gargs.quiet = true;
  81. if ((o = this.argv.output)) {
  82. args.push("--output", o, "--yes");
  83. }
  84. if (!this.argv.binary) {
  85. args.push("-a");
  86. }
  87. if (this.argv.message) {
  88. gargs.stdin = new BufferInStream(this.argv.message);
  89. } else if (this.argv.file != null) {
  90. args.push(this.argv.file);
  91. } else {
  92. gargs.stdin = process.stdin;
  93. }
  94. (function(_this) {
  95. return (function(__iced_k) {
  96. __iced_deferrals = new iced.Deferrals(__iced_k, {
  97. parent: ___iced_passed_deferral,
  98. filename: "/home/jacko/node-client/src/command/encrypt.iced",
  99. funcname: "Command.do_encrypt"
  100. });
  101. master_ring().gpg(gargs, __iced_deferrals.defer({
  102. assign_fn: (function() {
  103. return function() {
  104. err = arguments[0];
  105. return out = arguments[1];
  106. };
  107. })(),
  108. lineno: 70
  109. }));
  110. __iced_deferrals._fulfill();
  111. });
  112. })(this)((function(_this) {
  113. return function() {
  114. (function(__iced_k) {
  115. if (_this.argv.output == null) {
  116. (function(__iced_k) {
  117. if (_this.argv.binary) {
  118. (function(__iced_k) {
  119. __iced_deferrals = new iced.Deferrals(__iced_k, {
  120. parent: ___iced_passed_deferral,
  121. filename: "/home/jacko/node-client/src/command/encrypt.iced",
  122. funcname: "Command.do_encrypt"
  123. });
  124. process.stdout.write(out, __iced_deferrals.defer({
  125. lineno: 73
  126. }));
  127. __iced_deferrals._fulfill();
  128. })(__iced_k);
  129. } else {
  130. return __iced_k(log.console.log(out.toString('utf8')));
  131. }
  132. })(__iced_k);
  133. } else {
  134. return __iced_k();
  135. }
  136. })(function() {
  137. return cb(err);
  138. });
  139. };
  140. })(this));
  141. };
  142. Command.prototype.run = function(cb) {
  143. var assertions, batch, esc, them_un, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  144. __iced_k = __iced_k_noop;
  145. ___iced_passed_deferral = iced.findDeferral(arguments);
  146. esc = make_esc(cb, "Command::run");
  147. batch = !this.argv.message && (this.argv.file == null);
  148. if (this.argv.sign && !env().is_configured()) {
  149. cb(new Error("You can't sign messages when you aren't logged in."));
  150. return;
  151. }
  152. (function(_this) {
  153. return (function(__iced_k) {
  154. __iced_deferrals = new iced.Deferrals(__iced_k, {
  155. parent: ___iced_passed_deferral,
  156. filename: "/home/jacko/node-client/src/command/encrypt.iced",
  157. funcname: "Command.run"
  158. });
  159. User.resolve_user_name({
  160. username: _this.argv.them[0]
  161. }, esc(__iced_deferrals.defer({
  162. assign_fn: (function() {
  163. return function() {
  164. them_un = arguments[0];
  165. return assertions = arguments[1];
  166. };
  167. })(),
  168. lineno: 91
  169. })));
  170. __iced_deferrals._fulfill();
  171. });
  172. })(this)((function(_this) {
  173. return function() {
  174. (function(__iced_k) {
  175. if (env().is_me(them_un)) {
  176. _this.is_self = true;
  177. (function(__iced_k) {
  178. __iced_deferrals = new iced.Deferrals(__iced_k, {
  179. parent: ___iced_passed_deferral,
  180. filename: "/home/jacko/node-client/src/command/encrypt.iced",
  181. funcname: "Command.run"
  182. });
  183. User.load_me({
  184. secret: true
  185. }, esc(__iced_deferrals.defer({
  186. assign_fn: (function(__slot_1) {
  187. return function() {
  188. return __slot_1.them = arguments[0];
  189. };
  190. })(_this),
  191. lineno: 95
  192. })));
  193. __iced_deferrals._fulfill();
  194. })(__iced_k);
  195. } else {
  196. _this.is_self = false;
  197. _this.tssc = new TrackSubSubCommand({
  198. args: {
  199. them: them_un
  200. },
  201. opts: _this.argv,
  202. batch: batch,
  203. assertions: assertions
  204. });
  205. (function(__iced_k) {
  206. __iced_deferrals = new iced.Deferrals(__iced_k, {
  207. parent: ___iced_passed_deferral,
  208. filename: "/home/jacko/node-client/src/command/encrypt.iced",
  209. funcname: "Command.run"
  210. });
  211. _this.tssc.pre_encrypt(esc(__iced_deferrals.defer({
  212. lineno: 99
  213. })));
  214. __iced_deferrals._fulfill();
  215. })(function() {
  216. return __iced_k(_this.them = _this.tssc.them);
  217. });
  218. }
  219. })(function() {
  220. (function(__iced_k) {
  221. __iced_deferrals = new iced.Deferrals(__iced_k, {
  222. parent: ___iced_passed_deferral,
  223. filename: "/home/jacko/node-client/src/command/encrypt.iced",
  224. funcname: "Command.run"
  225. });
  226. _this.do_encrypt(esc(__iced_deferrals.defer({
  227. lineno: 101
  228. })));
  229. __iced_deferrals._fulfill();
  230. })(function() {
  231. return cb(null);
  232. });
  233. });
  234. };
  235. })(this));
  236. };
  237. return Command;
  238. })(Base);
  239. }).call(this);