public static CodeDirectoryBlob CreateCodeDirectoryBlob(int codeLength, string ident, string teamID, HashType hashType)
        {
            int pageSize = 4096;

            CodeDirectoryBlob codeDirectory = new CodeDirectoryBlob();

            codeDirectory.CodeLimit = (uint)codeLength;
            codeDirectory.HashType  = hashType;
            codeDirectory.HashSize  = (byte)HashAlgorithmHelper.GetHashLength(hashType);
            codeDirectory.PageSize  = pageSize;

            codeDirectory.Ident  = ident;
            codeDirectory.TeamID = teamID;
            // We put empty hashes as placeholder to ensure that the blob length will not change later.
            for (int index = 0; index < SpecialHashCount; index++)
            {
                codeDirectory.SpecialHashes.Add(new byte[codeDirectory.HashSize]);
            }
            int codeHashEntries = (int)Math.Ceiling((double)codeLength / pageSize);

            for (int index = 0; index < codeHashEntries; index++)
            {
                codeDirectory.CodeHashes.Add(new byte[codeDirectory.HashSize]);
            }

            return(codeDirectory);
        }
        public static void UpdateSpecialHashes(CodeDirectoryBlob codeDirectory, byte[] codeToHash, byte[] infoFileBytes, CodeRequirementsBlob codeRequirements, byte[] codeResourcesBytes, EntitlementsBlob entitlements)
        {
            codeDirectory.CodeHashes = HashAlgorithmHelper.ComputeHashes(codeDirectory.HashType, codeDirectory.PageSize, codeToHash);

            codeDirectory.SpecialHashes = new List <byte[]>();
            codeDirectory.SpecialHashes.Insert(0, (HashAlgorithmHelper.ComputeHash(codeDirectory.HashType, infoFileBytes)));
            codeDirectory.SpecialHashes.Insert(0, (HashAlgorithmHelper.ComputeHash(codeDirectory.HashType, codeRequirements.GetBytes())));
            codeDirectory.SpecialHashes.Insert(0, (HashAlgorithmHelper.ComputeHash(codeDirectory.HashType, codeResourcesBytes)));
            if (SpecialHashCount >= CodeDirectoryBlob.ApplicationSpecificHashOffset)
            {
                codeDirectory.SpecialHashes.Insert(0, new byte[HashAlgorithmHelper.GetHashLength(codeDirectory.HashType)]);
                if (SpecialHashCount >= CodeDirectoryBlob.EntitlementsHashOffset)
                {
                    codeDirectory.SpecialHashes.Insert(0, (HashAlgorithmHelper.ComputeHash(codeDirectory.HashType, entitlements.GetBytes())));
                }
            }
        }