pw.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var PasswordManager, crypto, iced, log, read, __iced_k, __iced_k_noop;
  4. iced = require('iced-runtime').iced;
  5. __iced_k = __iced_k_noop = function() {};
  6. read = require('read');
  7. log = require('./log');
  8. crypto = require('crypto');
  9. exports.PasswordManager = PasswordManager = (function() {
  10. function PasswordManager() {}
  11. PasswordManager.prototype.init = function(opts) {
  12. this.opts = opts;
  13. return true;
  14. };
  15. PasswordManager.prototype.get_opts = function() {
  16. return this.opts;
  17. };
  18. PasswordManager.prototype._prompt_1 = function(prompt, cb) {
  19. var err, res, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  20. __iced_k = __iced_k_noop;
  21. ___iced_passed_deferral = iced.findDeferral(arguments);
  22. (function(_this) {
  23. return (function(__iced_k) {
  24. __iced_deferrals = new iced.Deferrals(__iced_k, {
  25. parent: ___iced_passed_deferral,
  26. filename: "/Users/max/src/keybase/node-client/src/pw.iced",
  27. funcname: "PasswordManager._prompt_1"
  28. });
  29. read({
  30. prompt: "" + prompt + "> ",
  31. silent: true
  32. }, __iced_deferrals.defer({
  33. assign_fn: (function() {
  34. return function() {
  35. err = arguments[0];
  36. return res = arguments[1];
  37. };
  38. })(),
  39. lineno: 24
  40. }));
  41. __iced_deferrals._fulfill();
  42. });
  43. })(this)((function(_this) {
  44. return function() {
  45. if (err) {
  46. log.error("In prompt: " + err);
  47. res = null;
  48. } else if (res != null) {
  49. res = (res.split(/\s+/)).join('');
  50. if (res.length === 0) {
  51. res = null;
  52. }
  53. }
  54. return cb(res);
  55. };
  56. })(this));
  57. };
  58. PasswordManager.prototype.prompt_for_old_pw = function(cb) {
  59. var pw, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  60. __iced_k = __iced_k_noop;
  61. ___iced_passed_deferral = iced.findDeferral(arguments);
  62. (function(_this) {
  63. return (function(__iced_k) {
  64. __iced_deferrals = new iced.Deferrals(__iced_k, {
  65. parent: ___iced_passed_deferral,
  66. filename: "/Users/max/src/keybase/node-client/src/pw.iced",
  67. funcname: "PasswordManager.prompt_for_old_pw"
  68. });
  69. _this._prompt_1('password', __iced_deferrals.defer({
  70. assign_fn: (function() {
  71. return function() {
  72. return pw = arguments[0];
  73. };
  74. })(),
  75. lineno: 36
  76. }));
  77. __iced_deferrals._fulfill();
  78. });
  79. })(this)((function(_this) {
  80. return function() {
  81. return cb(pw);
  82. };
  83. })(this));
  84. };
  85. PasswordManager.prototype.prompt_for_pw = function(is_new, cb) {
  86. if (is_new) {
  87. return this.prompt_for_new_pw(cb);
  88. } else {
  89. return this.prompt_for_old_pw(cb);
  90. }
  91. };
  92. PasswordManager.prototype.prompt_for_new_pw = function(cb) {
  93. var go, pw1, pw2, res, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  94. __iced_k = __iced_k_noop;
  95. ___iced_passed_deferral = iced.findDeferral(arguments);
  96. go = true;
  97. res = null;
  98. (function(_this) {
  99. return (function(__iced_k) {
  100. var _results, _while;
  101. _results = [];
  102. _while = function(__iced_k) {
  103. var _break, _continue, _next;
  104. _break = function() {
  105. return __iced_k(_results);
  106. };
  107. _continue = function() {
  108. return iced.trampoline(function() {
  109. return _while(__iced_k);
  110. });
  111. };
  112. _next = function(__iced_next_arg) {
  113. _results.push(__iced_next_arg);
  114. return _continue();
  115. };
  116. if (!(go && !res)) {
  117. return _break();
  118. } else {
  119. (function(__iced_k) {
  120. __iced_deferrals = new iced.Deferrals(__iced_k, {
  121. parent: ___iced_passed_deferral,
  122. filename: "/Users/max/src/keybase/node-client/src/pw.iced",
  123. funcname: "PasswordManager.prompt_for_new_pw"
  124. });
  125. _this._prompt_1('passwrd', __iced_deferrals.defer({
  126. assign_fn: (function() {
  127. return function() {
  128. return pw1 = arguments[0];
  129. };
  130. })(),
  131. lineno: 50
  132. }));
  133. __iced_deferrals._fulfill();
  134. })(function() {
  135. (function(__iced_k) {
  136. if (typeof pw1 !== "undefined" && pw1 !== null) {
  137. (function(__iced_k) {
  138. __iced_deferrals = new iced.Deferrals(__iced_k, {
  139. parent: ___iced_passed_deferral,
  140. filename: "/Users/max/src/keybase/node-client/src/pw.iced",
  141. funcname: "PasswordManager.prompt_for_new_pw"
  142. });
  143. _this._prompt_1('confirm', __iced_deferrals.defer({
  144. assign_fn: (function() {
  145. return function() {
  146. return pw2 = arguments[0];
  147. };
  148. })(),
  149. lineno: 52
  150. }));
  151. __iced_deferrals._fulfill();
  152. })(function() {
  153. return __iced_k(pw1 === pw2 ? res = pw1 : log.warn("Password didn't match"));
  154. });
  155. } else {
  156. return __iced_k(go = false);
  157. }
  158. })(_next);
  159. });
  160. }
  161. };
  162. _while(__iced_k);
  163. });
  164. })(this)((function(_this) {
  165. return function() {
  166. return cb(res);
  167. };
  168. })(this));
  169. };
  170. PasswordManager.prototype.get_password = function(is_new, cb) {
  171. var pw, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  172. __iced_k = __iced_k_noop;
  173. ___iced_passed_deferral = iced.findDeferral(arguments);
  174. (function(_this) {
  175. return (function(__iced_k) {
  176. if (_this._pw == null) {
  177. (function(__iced_k) {
  178. if (((pw = _this.opts.password) == null) && _this.opts.interactive && !_this.opts.bg) {
  179. (function(__iced_k) {
  180. __iced_deferrals = new iced.Deferrals(__iced_k, {
  181. parent: ___iced_passed_deferral,
  182. filename: "/Users/max/src/keybase/node-client/src/pw.iced",
  183. funcname: "PasswordManager.get_password"
  184. });
  185. _this.prompt_for_pw(is_new, __iced_deferrals.defer({
  186. assign_fn: (function() {
  187. return function() {
  188. return pw = arguments[0];
  189. };
  190. })(),
  191. lineno: 64
  192. }));
  193. __iced_deferrals._fulfill();
  194. })(__iced_k);
  195. } else {
  196. return __iced_k();
  197. }
  198. })(function() {
  199. return __iced_k(_this._pw = pw);
  200. });
  201. } else {
  202. return __iced_k();
  203. }
  204. });
  205. })(this)((function(_this) {
  206. return function() {
  207. return cb(_this._pw);
  208. };
  209. })(this));
  210. };
  211. return PasswordManager;
  212. })();
  213. }).call(this);