Esempio n. 1
0
 // Implements RopPassCallBack
 public RopPassCallBack.Ret PassCallBack(RopHandle ffi, object ctx, RopHandle key, RopHandle pgpCtx, RopHandle buf, int bufLen)
 {
     if (passProvider != null)
     {
         // create new Session and Key handlers
         RopSession ropSes = null;
         RopKey     ropKey = null;
         try {
             if (own.TryGetTarget(out RopBind bind))
             {
                 ropSes = (!ffi.IsNull()? new RopSession(bind, ffi) : null);
                 ropKey = (!key.IsNull()? new RopKey(bind, key) : null);
                 SessionPassCallBack.Ret scbRet = passProvider.PassCallBack(ropSes, ctx, ropKey, RopHandle.Str(pgpCtx), bufLen);
                 return(new RopPassCallBack.Ret(scbRet.ret, scbRet.outBuf));
             }
             throw new RopError(RopBind.ROP_ERROR_INTERNAL);
         } catch (RopError) {
         } finally {
             if (ropSes != null)
             {
                 ropSes.Detach();
             }
             if (ropKey != null)
             {
                 ropKey.Detach();
             }
         }
     }
     return(new RopPassCallBack.Ret(false, null));
 }
Esempio n. 2
0
        public RopOpSign op_sign_create(RopInput input, RopOutput output, bool cleartext = false, bool detached = false, int tag = 0)
        {
            int       ret  = ROPE.RNP_SUCCESS;
            RopHandle inp  = (input != null? input.getHandle() : RopHandle.Null);
            RopHandle outp = (output != null? output.getHandle() : RopHandle.Null);
            RopHandle op   = null;

            if (cleartext)
            {
                ret = (int)lib.rnp_op_sign_cleartext_create(out op, sid, inp, outp);
            }
            else if (detached)
            {
                ret = (int)lib.rnp_op_sign_detached_create(out op, sid, inp, outp);
            }
            else
            {
                ret = (int)lib.rnp_op_sign_create(out op, sid, inp, outp);
            }
            if (own.TryGetTarget(out RopBind bind))
            {
                RopOpSign sign = new RopOpSign(bind, Util.PopHandle(lib, op, ret));
                bind.PutObj(sign, tag);
                return(sign);
            }
            throw new RopError(RopBind.ROP_ERROR_INTERNAL);
        }
Esempio n. 3
0
        public void export_revocation(RopOutput output, string hash, string code, string reason)
        {
            RopHandle outp = (output != null? output.getHandle() : RopHandle.Null);
            int       ret  = (int)lib.rnp_key_export_revocation(kid, outp, 0, hash, code, reason);

            Util.Return(ret);
        }
Esempio n. 4
0
 public static RopHandle PopHandle(RopLib rop, RopHandle val, int err)
 {
     if (err != ROPE.RNP_SUCCESS)
     {
         throw new RopError(err);
     }
     return(val);
 }
Esempio n. 5
0
        public void decrypt(RopInput input, RopOutput output)
        {
            RopHandle inp  = (input != null? input.getHandle() : RopHandle.Null);
            RopHandle outp = (output != null? output.getHandle() : RopHandle.Null);
            int       ret  = (int)lib.rnp_decrypt(sid, inp, outp);

            Util.Return(ret);
        }
Esempio n. 6
0
        public void export_autocrypt(RopKey subkey, string uid, RopOutput output)
        {
            RopHandle subk = (subkey != null? subkey.getHandle() : RopHandle.Null);
            RopHandle outp = (output != null? output.getHandle() : RopHandle.Null);
            int       ret  = (int)lib.rnp_key_export_autocrypt(kid, subk, uid, outp, 0);

            Util.Return(ret);
        }
Esempio n. 7
0
 internal RopData(RopBind own, RopHandle hnd, long dataLen)
 {
     this.lib     = own.getLib();
     this.hnd     = hnd;
     this.dataLen = dataLen;
     this.sdata   = null;
     this.bdata   = null;
 }
Esempio n. 8
0
 internal void Attach(RopHandle iid)
 {
     if (iid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.iid = iid;
 }
Esempio n. 9
0
 internal RopIdIterator(RopBind own, RopHandle iiid)
 {
     if (iiid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.lib  = own.getLib();
     this.iiid = iiid;
 }
Esempio n. 10
0
 public RopSignSignature(RopBind own, RopHandle sgid)
 {
     if (sgid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.lib  = own.getLib();
     this.sgid = sgid;
 }
Esempio n. 11
0
 internal RopSymEnc(RopBind own, RopHandle seid)
 {
     if (seid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.own  = new WeakReference <RopBind>(own);
     this.lib  = own.getLib();
     this.seid = seid;
 }
Esempio n. 12
0
        public void load_keys(string format, RopInput input, bool pub = true, bool sec = true)
        {
            RopHandle inp   = (input != null? input.getHandle() : RopHandle.Null);
            int       flags = (pub? ROPD.RNP_LOAD_SAVE_PUBLIC_KEYS : 0);

            flags |= (sec? ROPD.RNP_LOAD_SAVE_SECRET_KEYS : 0);
            int ret = (int)lib.rnp_load_keys(sid, format, inp, (uint)flags);

            Util.Return(ret);
        }
Esempio n. 13
0
 private RopKey PutKey(RopHandle keyHnd, int tag = 0)
 {
     if (own.TryGetTarget(out RopBind bind))
     {
         RopKey key = new RopKey(bind, keyHnd);
         bind.PutObj(key, tag);
         return(key);
     }
     throw new RopError(RopBind.ROP_ERROR_INTERNAL);
 }
Esempio n. 14
0
 public RopVeriSignature(RopBind own, RopHandle sgid)
 {
     if (sgid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.own  = new WeakReference <RopBind>(own);
     this.lib  = own.getLib();
     this.sgid = sgid;
 }
Esempio n. 15
0
 internal RopOpEncrypt(RopBind own, RopHandle opid)
 {
     if (opid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.own  = new WeakReference <RopBind>(own);
     this.lib  = own.getLib();
     this.opid = opid;
 }
Esempio n. 16
0
 internal RopRecipient(RopBind own, RopHandle rid)
 {
     if (rid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.own = new WeakReference <RopBind>(own);
     this.lib = own.getLib();
     this.rid = rid;
 }
Esempio n. 17
0
        public void save_keys(string format, RopOutput output, bool pub = true, bool sec = true)
        {
            RopHandle outp  = (output != null? output.getHandle() : RopHandle.Null);
            int       flags = (pub? ROPD.RNP_LOAD_SAVE_PUBLIC_KEYS : 0);

            flags |= (sec? ROPD.RNP_LOAD_SAVE_SECRET_KEYS : 0);
            int ret = (int)lib.rnp_save_keys(sid, format, outp, (uint)flags);

            Util.Return(ret);
        }
Esempio n. 18
0
        public String request_password(RopKey key, object context)
        {
            RopHandle hkey = (key != null? key.getHandle() : RopHandle.Null);
            int       ret  = (int)lib.rnp_request_password(sid, hkey, context, out RopHandle ps);
            RopHandle psw  = Util.PopHandle(lib, ps, ret);
            String    spsw = RopHandle.Str(psw);

            psw.ClearMemory();
            lib.rnp_buffer_destroy(psw);
            return(spsw);
        }
Esempio n. 19
0
 internal RopInput(RopBind own, RopHandle iid)
 {
     if (iid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.own     = new WeakReference <RopBind>(own);
     this.lib     = own.getLib();
     this.iid     = iid;
     this.inputCB = null;
 }
Esempio n. 20
0
 public bool OutputWriteCallBack(object ctx, RopHandle buf, long len)
 {
     if (outputCB != null && buf != null && len > 0)
     {
         if (own.TryGetTarget(out RopBind bind))
         {
             return(outputCB.WriteCallBack(ctx, new RopData(bind, buf, len)));
         }
         throw new RopError(RopBind.ROP_ERROR_INTERNAL);
     }
     return(false);
 }
Esempio n. 21
0
        public void export(RopOutput output, bool pub = true, bool sec = true, bool subkey = false, bool armored = false)
        {
            RopHandle outp  = (output != null? output.getHandle() : RopHandle.Null);
            int       flags = (pub? ROPD.RNP_KEY_EXPORT_PUBLIC : 0);

            flags |= (sec? ROPD.RNP_KEY_EXPORT_SECRET : 0);
            flags |= (subkey? ROPD.RNP_KEY_EXPORT_SUBKEYS : 0);
            flags |= (armored? ROPD.RNP_KEY_EXPORT_ARMORED : 0);
            int ret = (int)lib.rnp_key_export(kid, outp, (uint)flags);

            Util.Return(ret);
        }
Esempio n. 22
0
 internal RopSession(RopBind own, RopHandle sid)
 {
     if (sid.IsNull())
     {
         throw new RopError(RopBind.ROP_ERROR_NULL_HANDLE);
     }
     this.own          = new WeakReference <RopBind>(own);
     this.lib          = own.getLib();
     this.sid          = sid;
     this.passProvider = null;
     this.keyProvider  = null;
 }
Esempio n. 23
0
        public RopData import_signatures(RopInput input)
        {
            RopHandle inp = (input != null? input.getHandle() : RopHandle.Null);
            int       ret = (int)lib.rnp_import_signatures(sid, inp, 0, out RopHandle hnd);

            if (own.TryGetTarget(out RopBind bind))
            {
                RopData data = new RopData(bind, Util.PopHandle(lib, hnd, ret), 0);
                bind.PutObj(data, 0);
                return(data);
            }
            throw new RopError(RopBind.ROP_ERROR_INTERNAL);
        }
Esempio n. 24
0
 /**
  * @return string data
  */
 public string getString()
 {
     if (sdata != null)
     {
         return(sdata);
     }
     if (hnd != null && !hnd.IsNull())
     {
         string str = RopHandle.Str(hnd);
         return(str != null && 0 < dataLen && dataLen < str.Length? str.Substring(0, (int)dataLen) : str);
     }
     return(null);
 }
Esempio n. 25
0
        public RopOpEncrypt op_encrypt_create(RopInput input, RopOutput output, int tag = 0)
        {
            RopHandle inp  = (input != null? input.getHandle() : RopHandle.Null);
            RopHandle outp = (output != null? output.getHandle() : RopHandle.Null);
            int       ret  = (int)lib.rnp_op_encrypt_create(out RopHandle op, sid, inp, outp);

            if (own.TryGetTarget(out RopBind bind))
            {
                RopOpEncrypt ope = new RopOpEncrypt(bind, Util.PopHandle(lib, op, ret));
                bind.PutObj(ope, tag);
                return(ope);
            }
            throw new RopError(RopBind.ROP_ERROR_INTERNAL);
        }
Esempio n. 26
0
        public static string GetRopString(RopLib rop, int ret, RopHandle ropStr, bool freeBuf = true)
        {
            string sval = RopHandle.Str(ropStr);

            if (freeBuf)
            {
                rop.rnp_buffer_destroy(ropStr);
            }
            if (ret != ROPE.RNP_SUCCESS)
            {
                throw new RopError(ret);
            }
            return(sval);
        }
Esempio n. 27
0
 public static string[] GetRopStrings(RopLib rop, int ret, RopHandle[] ropStrs, bool freeBuf = true)
 {
     string[] svals = new string[ropStrs.Length];
     for (int idx = 0; idx < ropStrs.Length; idx++)
     {
         svals[idx] = RopHandle.Str(ropStrs[idx]);
         if (freeBuf)
         {
             rop.rnp_buffer_destroy(ropStrs[idx]);
         }
     }
     if (ret != ROPE.RNP_SUCCESS)
     {
         throw new RopError(ret);
     }
     return(svals);
 }
Esempio n. 28
0
        public RopOpGenerate op_generate_create(string keyAlg, RopKey primary = null, int tag = 0)
        {
            int       ret;
            RopHandle op = null;

            if (primary == null)
            {
                ret = (int)lib.rnp_op_generate_create(out op, sid, keyAlg);
            }
            else
            {
                ret = (int)lib.rnp_op_generate_subkey_create(out op, sid, primary != null? primary.getHandle() : RopHandle.Null, keyAlg);
            }
            if (own.TryGetTarget(out RopBind bind))
            {
                RopOpGenerate opg = new RopOpGenerate(bind, Util.PopHandle(lib, op, ret));
                bind.PutObj(opg, tag);
                return(opg);
            }
            throw new RopError(RopBind.ROP_ERROR_INTERNAL);
        }
Esempio n. 29
0
 // Implements RopKeyCallBack
 public void KeyCallBack(RopHandle ffi, object ctx, RopHandle identifierType, RopHandle identifier, bool secret)
 {
     if (keyProvider != null)
     {
         // create a new Session handler
         RopSession ropSes = null;
         try {
             if (own.TryGetTarget(out RopBind bind))
             {
                 ropSes = (!ffi.IsNull()? new RopSession(bind, ffi) : null);
                 keyProvider.KeyCallBack(ropSes, ctx, RopHandle.Str(identifierType), RopHandle.Str(identifier), secret);
             }
             throw new RopError(RopBind.ROP_ERROR_INTERNAL);
         } catch (RopError) {
         } finally {
             if (ropSes != null)
             {
                 ropSes.Detach();
             }
         }
     }
 }
Esempio n. 30
0
        public RopData import_keys(RopInput input, bool pub = true, bool sec = true, bool perm = false, bool sngl = false)
        {
            RopHandle inp   = (input != null? input.getHandle() : RopHandle.Null);
            int       flags = (pub? ROPD.RNP_LOAD_SAVE_PUBLIC_KEYS : 0);

            flags |= (sec? ROPD.RNP_LOAD_SAVE_SECRET_KEYS : 0);
            flags |= (perm? ROPD.RNP_LOAD_SAVE_PERMISSIVE : 0);
            flags |= (sngl? ROPD.RNP_LOAD_SAVE_SINGLE : 0);
            int ret = (int)lib.rnp_import_keys(sid, inp, (uint)flags, out RopHandle hnd);

            if (own.TryGetTarget(out RopBind bind))
            {
                hnd = Util.PopHandle(lib, hnd, ret != ROPE.RNP_ERROR_EOF? ret : ROPE.RNP_SUCCESS);
                if (ret != ROPE.RNP_ERROR_EOF)
                {
                    RopData data = new RopData(bind, hnd, 0);
                    bind.PutObj(data, 0);
                    return(data);
                }
                return(null);
            }
            throw new RopError(RopBind.ROP_ERROR_INTERNAL);
        }