コード例 #1
0
        public byte[] serialize()
        {
            Dictionary <string, byte[]> brdata = new Dictionary <string, byte[]>();

            // -"-v1"
            // BackupTime = DateTime.Ticks
            // BackupMessage = Encoding.UTF8.GetBytes(string)
            // MetadataTreeHashes = enum_encode(List<byte[]>)

            // -v2
            // Breaks compatability
            // v1 - MetadataTreeHashes +
            // MetadataTreeHash = byte[]

            // -v3
            // v2 +
            // UUID = byte[]

            // -v4
            // MetadataTreeMultiBlock = BitConverter.GetBytes(bool)
            // -v5
            // removed MetadataTreeMultiBlock


            brdata.Add("BackupTime-v1", BitConverter.GetBytes(BackupTime.Ticks));
            brdata.Add("BackupMessage-v1", Encoding.UTF8.GetBytes(BackupMessage));

            brdata.Add("MetadataTreeHash-v2", MetadataTreeHash);

            brdata.Add("UUID-v3", UUID);

            return(BinaryEncoding.dict_encode(brdata));
        }
コード例 #2
0
            public byte[] serialize()
            {
                Dictionary <string, byte[]> bsrData = new Dictionary <string, byte[]>
                {
                    // -"-v1"
                    // Required:
                    // BackupSet = Encoding.UTF8.GetBytes(string)
                    // Shallow = BitConverter.GetBytes(bool)
                    // BlobListCache = BitConverter.GetBytes(bool)
                    { "BackupSet-v1", Encoding.UTF8.GetBytes(BackupSetName) },
                    { "Shallow-v1", BitConverter.GetBytes(Shallow) },
                    { "BlobListCache-v1", BitConverter.GetBytes(BlobListCache) }
                };

                return(BinaryEncoding.dict_encode(bsrData));
            }
コード例 #3
0
        /// <summary>
        /// Store encrypted data key and other info needed to
        /// regenerate AesHelper given a password.
        /// </summary>
        /// <returns></returns>
        public byte[] CreateKeyFile()
        {
            Dictionary <string, byte[]> kfdata = new Dictionary <string, byte[]>();

            // -"-v1"
            // passwordsalt
            // datakeykeyhash
            // datakeykeyhashsalt
            // encrypteddatakey
            // datakeyiv
            kfdata.Add("passwordsalt-v1", PasswordSalt);
            kfdata.Add("datakeykeyhash-v1", DataKeyKeyHash);
            kfdata.Add("datakeykeyhashsalt-v1", DataKeyKeyHashSalt);
            kfdata.Add("encrypteddatakey-v1", EncryptAesDataKey());
            kfdata.Add("datakeyiv-v1", DataKeyIV);
            return(BinaryEncoding.dict_encode(kfdata));
        }
コード例 #4
0
        public byte[] serialize()
        {
            Dictionary <string, byte[]> bldata = new Dictionary <string, byte[]>();

            // -"-v1"
            // RelativeFilePath = Encoding.UTF8.GetBytes(string)
            // BytePosition = BitConverter.GetBytes(int)
            // ByteLength = BitConverter.GetBytes(int)
            // -"-v2"
            // BlobType = BitConverter.GetBytes(int)
            // -v3
            // Required: breaks compatability
            // ReferenceCount = BitConverter.GetBytes(int)
            // -v4
            // Required
            // IsMultiBlockReference = BitConverter.GetBytes(bool)
            // -v5
            // Required
            // BSetReferenceCounts.BackupSets =
            // BSetReferenceCounts.ReferenceCounts =
            // -v6
            // BlobType removed
            // IsMultiBlockReference removed
            // -v7
            // IsMultiBlockReference readded
            // -v8
            // BlockHashes = enum_encode
            // -v9
            // EncryptedHash = bytes

            bldata.Add("EncryptedHash-v9", EncryptedHash == null ? new byte[0] : EncryptedHash);
            bldata.Add("RelativeFilePath-v1", Encoding.UTF8.GetBytes(RelativeFilePath));
            bldata.Add("ByteLength-v1", BitConverter.GetBytes(ByteLength));

            bldata.Add("BSetReferenceCounts.BackupSets-v5", BinaryEncoding.enum_encode(BSetReferenceCounts.Keys.Select(bsr => bsr.serialize())));
            bldata.Add("BSetReferenceCounts.ReferenceCounts-v5", BinaryEncoding.enum_encode(BSetReferenceCounts.Values.Select(rc => BitConverter.GetBytes(rc))));

            bldata.Add("IsMultiBlockReference-v7", BitConverter.GetBytes(BlockHashes != null));
            if (BlockHashes != null)
            {
                bldata.Add("BlockHashes-v8", BinaryEncoding.enum_encode(BlockHashes));
            }

            return(BinaryEncoding.dict_encode(bldata));
        }
コード例 #5
0
ファイル: FileMetadata.cs プロジェクト: weirdev/lagern
        public byte[] serialize()
        {
            Dictionary <string, byte[]> fmdata = new Dictionary <string, byte[]>();

            // v1
            // -"-v1" (suffix for below)
            // FileName = UTF8 encoded
            // DateAccessedUTC = BitConverter.GetBytes(long NumDateAccessedUTC)
            // DateModifiedUTC = BitConverter.GetBytes(long NumDateModifiedUTC)
            // DateCreatedUTC = BitConverter.GetBytes(long NumDateCreatedUTC)
            // FileSize = BitConverter.GetBytes(long)
            // BlocksHashes = enum_encode(BlocksHashes) or byte[0] if BlocksHashes==null

            // -v2
            // all v1 data (suffix unchanged) +
            // Attributes = BitConverter.GetBytes((int)Attributes)

            // -v3
            // Breaks compatibility with v1&v2
            // all v2 data +
            // FileHash = FileHash or byte[0] if FileHash==null

            // -v4
            // MultiBlock = BitConverter.GetBytes(bool)
            // -v5
            // removed MultiBlock

            fmdata.Add("FileName-v1", Encoding.UTF8.GetBytes(FileName));
            fmdata.Add("DateAccessedUTC-v1", BitConverter.GetBytes(NumDateAccessedUTC));
            fmdata.Add("DateModifiedUTC-v1", BitConverter.GetBytes(NumDateModifiedUTC));
            fmdata.Add("DateCreatedUTC-v1", BitConverter.GetBytes(NumDateCreatedUTC));
            fmdata.Add("FileSize-v1", BitConverter.GetBytes(FileSize));

            fmdata.Add("Attributes-v2", BitConverter.GetBytes((int)Attributes));
            if (FileHash != null)
            {
                fmdata.Add("FileHash-v3", FileHash);
            }
            else
            {
                fmdata.Add("FileHash-v3", new byte[0]);
            }

            return(BinaryEncoding.dict_encode(fmdata));
        }
コード例 #6
0
        /// <summary>
        /// Store this node and its descendents in a blobstore
        /// Breaks with circular references, but these should only occur
        /// with hard- (and soft-?) -links TODO: handle links
        /// </summary>
        /// <param name="blobs"></param>
        /// <param name="storeGetHash">Function called to store node data, returns hash</param>
        /// <returns>The hash of the stored tree and a tree of its child hashes.</returns>
        public (byte[] nodehash, HashTreeNode node) Store(Func <byte[], byte[]> storeGetHash)
        {
            List <(byte[] nodehash, HashTreeNode?node)> children = new List <(byte[] nodehash, HashTreeNode?node)>();
            List <byte[]> dirhashes = new List <byte[]>();

            foreach (MetadataNode dir in Directories.Values)
            {
                var(newhash, newnode) = dir.Store(storeGetHash);
                dirhashes.Add(newhash);
                children.Add((newhash, newnode));
            }
            foreach (var fm in Files.Values.AsEnumerable())
            {
                if (fm.FileHash == null)
                {
                    throw new NullReferenceException("Stored filehashes cannot be null");
                }
                children.Add((fm.FileHash, null));
            }
            Dictionary <string, byte[]> mtdata = new Dictionary <string, byte[]>();

            // -"-v1"
            // DirMetadata = FileMetadata DirMetadata.serialize()
            // Directories = enum_encode([Directories.Values MetadataNode.serialize(),... ])
            // Files = enum_encode([Files.Values FileMetadata.serialize(),... ])
            // -"-v2"
            // Directories = enum_encode([dirrefs,...])
            // "-v3"
            // DirectoriesMultiblock = enum_encode([BitConverter.GetBytes(multiblock),...])
            // -v4
            // removed DirectoriesMultiblock
            mtdata.Add("DirMetadata-v1", DirMetadata.serialize());
            mtdata.Add("Files-v1", BinaryEncoding.enum_encode(Files.Values.AsEnumerable()
                                                              .Select(fm => fm.serialize())));

            mtdata.Add("Directories-v2", BinaryEncoding.enum_encode(dirhashes));

            byte[]       nodehash = storeGetHash(BinaryEncoding.dict_encode(mtdata));
            HashTreeNode node     = new HashTreeNode(children);

            return(nodehash, node);
        }