public ResourceEntry ToResourceEntry(IEncryption encryption, MamChannelFactory channelFactory, MamChannelSubscriptionFactory subscriptionFactory)
        {
            var decryptedChannel      = encryption.Decrypt(this.Channel);
            var decryptedSubscription = encryption.Decrypt(this.Subscription);

            return(new ResourceEntry
            {
                ResourceRoots = this.Roots.Split(';').ToList(),
                Channel = string.IsNullOrEmpty(decryptedChannel) ? null : channelFactory.CreateFromJson(decryptedChannel),
                Subscription = subscriptionFactory.CreateFromJson(decryptedSubscription)
            });
        }
Exemple #2
0
        public async Task TestMamChannelRecreation()
        {
            var seed = new Seed("JETCPWLCYRM9XYQMMZIFZLDBZZEWRMRVGWGGNCUH9LFNEHKEMLXAVEOFFVOATCNKVKELNQFAGOVUNWEJI");

            var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, new InMemoryIotaRepository());
            var channelKey     = new TryteString("NXRZEZIKWGKIYDPVBRKWLYTWLUVSDLDCHVVSVIWDCIUZRAKPJUIABQDZBV9EGTJWUFTIGAUT9STIENCBC");
            var channel        = channelFactory.Create(Mode.Restricted, seed, SecurityLevel.Medium, channelKey);

            var message = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone!"));
            await channel.PublishAsync(message);

            var serializedChannel   = channel.ToJson();
            var unserializedChannel = channelFactory.CreateFromJson(serializedChannel);

            Assert.AreEqual(channel.Index, unserializedChannel.Index);
            Assert.AreEqual(channel.Start, unserializedChannel.Start);
            Assert.AreEqual(channel.NextCount, unserializedChannel.NextCount);
            Assert.AreEqual(channel.Count, unserializedChannel.Count);
            Assert.AreEqual(channel.NextRoot.Value, unserializedChannel.NextRoot.Value);
            Assert.AreEqual(channel.Seed.Value, unserializedChannel.Seed.Value);
            Assert.AreEqual(channel.SecurityLevel, unserializedChannel.SecurityLevel);
            Assert.AreEqual(channel.Key.Value, unserializedChannel.Key.Value);
            Assert.AreEqual(channel.Mode, unserializedChannel.Mode);
        }