Exemple #1
0
        public static void Main(string[] args, KeyStorage keyStorage)
        {
            if (args.Length != 4)
            {
                throw new HelpException("Missing arguments");
            }

            //Storage
            Repo repo = Repo.Create(args [1]);

            repo = new EncryptedRepo(repo, keyStorage);

            //Find message
            Chunk chunk = null;

            if (args [2].Length == 64)
            {
                ChunkHash id = ChunkHash.FromHashBytes(Hash.FromString(args [2]).bytes);
                chunk = repo.ReadChunk(id);
            }
            else
            {
                ICollection <ChunkHash> messages = repo.GetMessageList("file");
                foreach (ChunkHash bh in messages)
                {
                    if (bh.ToString().StartsWith(args [2]))
                    {
                        chunk = repo.ReadChunk(bh);
                    }
                }
            }

            Message message = Message.FromChunk(chunk, keyStorage);

            if (message == null)
            {
                Console.Error.WriteLine("Message not found");
                return;
            }
            TreeMessage tm = message as TreeMessage;

            if (tm == null)
            {
                Console.Error.WriteLine("Not a TreeMessage: " + message.GetType().Name);
                return;
            }

            Console.WriteLine("Found TreeMessage " + tm.Name);
            string targetPath = Path.Combine(args [3], tm.Name);

            TreeChunk.Extract(repo, ChunkHash.FromHashBytes(tm.TreeChunkHash), targetPath);
        }
Exemple #2
0
        public static void Main(string[] args, KeyStorage keyStorage)
        {
            if (args.Length != 2)
            {
                throw new HelpException("Missing arguments");
            }

            //Repo
            Repo repo = Repo.Create(args [1]);

            //Find message
            ICollection <ChunkHash> messages = repo.GetMessageList("file");
            EncryptedRepo           es       = new EncryptedRepo(repo, keyStorage);

            //Iterate over all messages
            foreach (ChunkHash mid in messages)
            {
                Console.Write(mid.ToString().Substring(0, 10) + "... ");

                Message message = Message.FromChunk(es.ReadChunk(mid), keyStorage);

                //No key found
                if (message == null)
                {
                    Console.WriteLine("no key");
                    continue;
                }

                if (message.Signature != null)
                {
                    Console.Write("(signed by " + message.Signature.Name + ") ");
                }

                TreeMessage tm = message as TreeMessage;
                if (tm != null)
                {
                    Console.WriteLine("TreeMessage " + tm.Name);
                    continue;
                }

                RouteMessage rm = message as RouteMessage;
                if (rm != null)
                {
                    Console.WriteLine("RouteMessage to " + rm.To);
                    continue;
                }

                Console.WriteLine("unknown message type: " + message.GetType().Name);
            }
        }