 {RSA} = require './rsa'
 K = require('./const').kb
 {make_esc} = require 'iced-error'
+{bufferify} = require './util'
 
 #=================================================================
 
 class Encryption 
-  constructor : ({@tsenc, @passphrase}) ->
+  constructor : ({@tsenc, passphrase}) ->
+    @passphrase = bufferify passphrase
+    @tsenc or= new triplesec.Encryptor { version : 2, @passphrase }
 
 #=================================================================
 

    ring = new Bundle { primary, subkeys, userids }
    cb null, ring

  @import_from_armored_pgp_private : ({raw, passphrase, asp}, cb) ->

  @import_from_armored_pgp_public : ({raw, asp}, cb) ->

  # The export consists of
  #   1. A PGP message (potentially redacted from upload)
  #   2. A keybase message (Public key only)
  export_to_server_public_only : ({asp}, cb) ->

  # A private export consists of:
  #   1. The redacted PGP message
  #   2. The keybase message (Public and private keys)
  export_to_server_private : ({asp}, cb) ->

  # Export to a PGP PRIVATE KEY BLOCK, stored in PGP format
  # We'll need to reencrypt with a derived 
  export_to_client : (cb) ->

  sign_pgp : ({asp}, cb) ->

  sign_keybase : ({asp}, cb) ->

class Bundle

  constructor : ({@primary, @subkeys, @userids}) ->
    @tsenc = null

  #========================
  # Public Interface

  # Generate a new key bunlde from scratch.  Make the given number
  # of subkeys.
  @generate : ({asp, nsubs, userids }, cb) ->
    esc = make_esc cb, "Bundle::generate"
    asp.section "primary"
