Exemplo n.º 1
0
        public void RandomAppCreate()
        {
            var appPtr = IntPtr.Zero;

            Assert.DoesNotThrow(() => appPtr = MockAuthResolver.Current.TestCreateApp());
            Assert.AreNotEqual(appPtr, IntPtr.Zero);
            Session.AppPtr = appPtr;
            Assert.DoesNotThrowAsync(async() => await MDataEntryActions.NewAsync());
        }
Exemplo n.º 2
0
        public async Task RandomPrivateMutableDataUpdateAction()
        {
            Utils.InitialiseSessionForRandomTestApp();
            const ulong  tagType  = 15001;
            const string actKey   = "sample_key";
            const string actValue = "sample_value";

            using (var mdInfoHandle = await MDataInfo.RandomPrivateAsync(tagType)) {
                using (var permissionSetH = await MDataPermissionSet.NewAsync()) {
                    await MDataPermissionSet.AllowAsync(permissionSetH, MDataAction.Insert);

                    await MDataPermissionSet.AllowAsync(permissionSetH, MDataAction.ManagePermissions);

                    using (var permissionsH = await MDataPermissions.NewAsync()) {
                        using (var appSignKeyH = await Crypto.AppPubSignKeyAsync()) {
                            await MDataPermissions.InsertAsync(permissionsH, appSignKeyH, permissionSetH);

                            await MData.MData.PutAsync(mdInfoHandle, permissionsH, NativeHandle.Zero);
                        }
                    }
                }
                using (var entryActionsH = await MDataEntryActions.NewAsync()) {
                    var key   = Encoding.Default.GetBytes(actKey).ToList();
                    var value = Encoding.Default.GetBytes(actValue).ToList();
                    key = await MDataInfo.EncryptEntryKeyAsync(mdInfoHandle, key);

                    value = await MDataInfo.EncryptEntryValueAsync(mdInfoHandle, value);

                    await MDataEntryActions.InsertAsync(entryActionsH, key, value);

                    await MData.MData.MutateEntriesAsync(mdInfoHandle, entryActionsH);
                }

                using (var keysHandle = await MData.MData.ListKeysAsync(mdInfoHandle)) {
                    var len = await MDataKeys.LenAsync(keysHandle);

                    Assert.AreEqual(1, len.ToInt32());
                }

                using (var entriesHandle = await MData.MData.ListEntriesAsync(mdInfoHandle)) {
                    var entries = await MDataEntries.ForEachAsync(entriesHandle);

                    Assert.AreEqual(1, entries.Count);
                    var entry = entries.First();
                    var key   = await MDataInfo.DecryptAsync(mdInfoHandle, entry.Item1);

                    var value = await MDataInfo.DecryptAsync(mdInfoHandle, entry.Item2);

                    var encoding = new ASCIIEncoding();
                    Assert.AreEqual(actKey, encoding.GetString(key.ToArray()));
                    Assert.AreEqual(actValue, encoding.GetString(value.ToArray()));
                }
            }
        }
Exemplo n.º 3
0
        public EventStoreImDProtocol(string appId, Session session)
        {
            AppContainerPath = $"apps/{appId}";

            _session           = session;
            _mDataInfo         = session.MDataInfoActions;
            _mData             = session.MData;
            _mDataPermissions  = session.MDataPermissions;
            _crypto            = session.Crypto;
            _accessContainer   = session.AccessContainer;
            _mDataEntryActions = session.MDataEntryActions;
            _mDataEntries      = session.MDataEntries;
            _iData             = session.IData;
            _cipherOpt         = session.CipherOpt;
        }
Exemplo n.º 4
0
        private void Init(IntPtr appPtr, GCHandle disconnectedHandle)
        {
            IsDisconnected      = false;
            _appPtr             = new SafeAppPtr(appPtr);
            _disconnectedHandle = disconnectedHandle;

            AccessContainer   = new AccessContainer(_appPtr);
            Crypto            = new Crypto(_appPtr);
            CipherOpt         = new CipherOpt(_appPtr);
            IData             = new IData.IData(_appPtr);
            MData             = new MData.MData(_appPtr);
            MDataEntries      = new MDataEntries(_appPtr);
            MDataEntryActions = new MDataEntryActions(_appPtr);
            MDataInfoActions  = new MDataInfoActions(_appPtr);
            MDataPermissions  = new MDataPermissions(_appPtr);
            NFS = new NFS(_appPtr);
        }
Exemplo n.º 5
0
        public async Task RandomPublicMutableDataInsertAction()
        {
            Utils.InitialiseSessionForRandomTestApp();
            const ulong tagType = 15001;

            using (var mdInfoHandle = await MDataInfo.RandomPublicAsync(tagType)) {
                using (var permissionSetH = await MDataPermissionSet.NewAsync()) {
                    await MDataPermissionSet.AllowAsync(permissionSetH, MDataAction.Insert);

                    await MDataPermissionSet.AllowAsync(permissionSetH, MDataAction.ManagePermissions);

                    using (var permissionsH = await MDataPermissions.NewAsync()) {
                        using (var appSignKeyH = await Crypto.AppPubSignKeyAsync()) {
                            await MDataPermissions.InsertAsync(permissionsH, appSignKeyH, permissionSetH);

                            await MData.MData.PutAsync(mdInfoHandle, permissionsH, NativeHandle.Zero);
                        }
                    }
                }
                using (var entryActionsH = await MDataEntryActions.NewAsync()) {
                    var key   = Encoding.Default.GetBytes("sample_key").ToList();
                    var value = Encoding.Default.GetBytes("sample_value").ToList();
                    await MDataEntryActions.InsertAsync(entryActionsH, key, value);

                    await MData.MData.MutateEntriesAsync(mdInfoHandle, entryActionsH);
                }

                using (var entryActionsH = await MDataEntryActions.NewAsync()) {
                    var key   = Encoding.Default.GetBytes("sample_key_2").ToList();
                    var value = Encoding.Default.GetBytes("sample_value_2").ToList();
                    await MDataEntryActions.InsertAsync(entryActionsH, key, value);

                    await MData.MData.MutateEntriesAsync(mdInfoHandle, entryActionsH);
                }

                using (var keysHandle = await MData.MData.ListKeysAsync(mdInfoHandle)) {
                    var len = await MDataKeys.LenAsync(keysHandle);

                    Assert.AreEqual(2, len.ToInt32());
                }
            }
        }