当前位置: 首页>>代码示例>>C#>>正文


C# Marshaller.Put方法代码示例

本文整理汇总了C#中Marshaller.Put方法的典型用法代码示例。如果您正苦于以下问题:C# Marshaller.Put方法的具体用法?C# Marshaller.Put怎么用?C# Marshaller.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Marshaller的用法示例。


在下文中一共展示了Marshaller.Put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatError

 /// <summary>
 /// Create a 10 byte error response that matches TPM error responses.
 /// </summary>
 /// <param name="errorCode"></param>
 /// <returns></returns>
 private byte[] FormatError(TpmRc errorCode)
 {
     var m = new Marshaller();
     m.Put(TpmSt.NoSessions, "");
     m.Put((uint)10, "");
     m.Put(errorCode, "");
     return m.GetBytes();
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:13,代码来源:SlotManager.cs

示例2: ToNet

 internal override void ToNet(Marshaller m)
 {
     if (Algorithm == TpmAlgId.Xor)
     {
         Globs.Throw<NotImplementedException>("SymDefObject.ToNet: XOR is not supported");
     }
     m.Put(Algorithm, "algorithm");
     if (Algorithm == TpmAlgId.None || Algorithm == TpmAlgId.Null)
     {
         return;
     }
     m.Put(KeyBits, "keyBits");
     m.Put(Mode, "mode");
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:14,代码来源:TpmCustomDefs.cs

示例3: CreateResponse

        public static byte[] CreateResponse(
            TpmRc responseCode,
            TpmHandle[] handles,
            SessionOut[] sessions,
            byte[] responseParmsNoHandles)
        {
            var m = new Marshaller();
            TpmSt tag = sessions.Length == 0 ? TpmSt.NoSessions : TpmSt.Sessions;

            m.Put(tag, "tag");
            m.PushLength(4);
            m.Put(responseCode, "responseCode");

            foreach (TpmHandle h in handles)
            {
                m.Put(h, "handle");
            }

            if (tag == TpmSt.Sessions)
            {
                m.Put((uint)responseParmsNoHandles.Length, "parmsLenght");
            }

            m.Put(responseParmsNoHandles, "parms");
            foreach (SessionOut s in sessions)
                m.Put(s, "session");
            m.PopAndSetLengthToTotalLength();
            return m.GetBytes();
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:29,代码来源:Tpm2.cs

示例4: ToNet

 /// <summary>
 /// Implements marshaling logic for most of the TPM object types.
 /// Can be overridden if a custom marshaling logic is required (e.g. when
 /// marshaling of a field depends on other field's value).
 /// </summary>
 /// <returns></returns>
 internal virtual void ToNet(Marshaller m)
 {
     var members = GetFieldsToMarshal();
     dbg.Indent();
     for (int i = 0; i < members.Length; ++i)
     {
         var mem = members[i];
         object memVal = Globs.GetMember(mem, this);
         dbg.Trace(i + ": " + mem.Name  +  " = " + memVal);
         if (mem.SizeLength > 0)
         {
             bool arr = mem.WireType == MarshalType.VariableLengthArray;
             int len = arr ? (memVal == null ? 0 : ((Array)memVal).Length)
                           : Marshaller.GetTpmRepresentation(memVal).Length;
             dbg.Trace("Sending " + (arr ? "Array " : "Struct ") + mem.Name + " of size " + len);
             m.PutSizeTag(len, mem.SizeLength, mem.SizeName);
         }
         m.Put(memVal, mem.Name);
     }
     dbg.Unindent();
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:27,代码来源:TpmBaseClasses.cs

示例5: DispatchMethod


//.........这里部分代码省略.........
                    ProcessResponseSessions(outSessions);
                    int offset = (int)commandInfo.HandleCountOut * 4;
                    outParmsWithHandles = DoParmEncryption(outParmsWithHandles, commandInfo, offset, Direction.Response);
                    var m = new Marshaller(outParmsWithHandles);
                    outParms = (TpmStructureBase)m.Get(expectedResponseType, "");
#if false
                    m = new Marshaller(command);
                    TpmSt tag = m.Get<TpmSt>();
                    uint cmdSize = m.Get<uint>();
                    TpmCc actualCmd = m.Get<TpmCc>();
                    var actualHandles = new TpmHandle[inHandles.Length];
                    for (int i = 0; i < inHandles.Length; ++i)
                    {
                        actualHandles[i] = m.Get<TpmHandle>();
                    }
                    for (int i = 0; i < inSessions.Length; ++i)
                    {
                        m.Get<SessionIn>();
                    }
                    var actualParms = m.GetArray<byte>(m.GetValidLength() - m.GetGetPos());
                    if (m.GetValidLength() != cmdSize)
                    {
                        throw new Exception("Command length in header does not match input byte-stream");
                    }
#endif
                    CommandHeader actualHeader;
                    TpmHandle[] actualHandles;
                    SessionIn[] actualSessions;
                    byte[] actualParmsBuf;
                    CommandProcessor.CrackCommand(command, out actualHeader, out actualHandles, out actualSessions, out actualParmsBuf);
                    m = new Marshaller();
                    foreach (TpmHandle h in actualHandles)
                    {
                        m.Put(h, "handle");
                    }
                    m.Put(actualParmsBuf, "parms");
                    var actualParms = (TpmStructureBase)Activator.CreateInstance(inParms.GetType());
                    actualParms.ToHost(m);
                    UpdateHandleData(actualHeader.CommandCode, actualParms, actualHandles, outParms);
                    //ValidateResponseSessions(outHandles, outSessions, ordinal, resultCode, outParmsNoHandles);

                    foreach (var h in outHandles)
                    {
                        CancelSafeFlushContext(h);
                    }
                } // if (repeat && resultCode == TpmRc.Success)
            }
            catch (Exception)
            {
                _ClearCommandPrelaunchContext();
                _ClearCommandContext();
                throw;
            }
            while (repeat);

            // Update the audit session if needed
            if (AuditThisCommand)
            {
                AuditThisCommand = false;
                if (CommandAuditHash == null)
                    throw new Exception("No audit hash set for this command stream");
                byte[] parmHash = GetCommandHash(CommandAuditHash.HashAlg, parms, inHandles);
                byte[] expectedResponseHash = GetExpectedResponseHash(CommandAuditHash.HashAlg,
                                                                      outParmsNoHandles,
                                                                      ordinal,
                                                                      resultCode);
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:67,代码来源:Tpm2.cs

示例6: GetExpectedResponseHash

        /// <summary>
        /// The response hash includes the command ordinal, response code, and the actual command bytes.
        /// </summary>
        /// <param name="hashAlg"></param>
        /// <param name="commandCode"></param>
        /// <param name="responseCode"></param>
        /// <param name="responseParmsNoHandles"></param>
        /// <returns></returns>
        private byte[] GetExpectedResponseHash(
            TpmAlgId hashAlg,
            byte[] responseParmsNoHandles,
            TpmCc commandCode,
            TpmRc responseCode)
        {
            var temp = new Marshaller();
            temp.Put(responseCode, "responseCode");
            temp.Put(commandCode, "currentCommand");
            temp.Put(responseParmsNoHandles, null);

            byte[] parmsHash = CryptoLib.HashData(hashAlg, temp.GetBytes());
            return parmsHash;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:22,代码来源:Tpm2.cs

示例7: GetPolicyDigest

        internal override TpmHash GetPolicyDigest(TpmAlgId hashAlg)
        {
            TpmCc commandCode = 0;
            if (TicketType == TpmSt.AuthSecret)
                commandCode = TpmCc.PolicySecret;
            else if (TicketType == TpmSt.AuthSigned)
                commandCode = TpmCc.PolicySigned;
            else
            {
                Globs.Throw<ArgumentException>("Ticket type is not recognized");
                return new TpmHash(hashAlg);
            }

            if (ObjectName == null)
            {
                ObjectName = AuthorizingKey.GetName();
            }
            var m = new Marshaller();
            m.Put(commandCode, "ordinal");
            m.Put(ObjectName, "name");

            // ReSharper disable once UnusedVariable
            TpmHash atStart = GetNextAcePolicyDigest(hashAlg);
            TpmHash firstExtend = GetNextAcePolicyDigest(hashAlg).Extend(m.GetBytes());
            TpmHash secondExtend = firstExtend.Extend(PolicyRef);

            return secondExtend;
        }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:28,代码来源:PolicyAces.cs

示例8: ToNet

 internal override void ToNet(Marshaller m)
 {
     if (CryptoLib.DigestSize(HashAlg) != HashData.Length)
     {
         if (!Tpm2._TssBehavior.Passthrough)
         {
             throw new Exception("Hash data length does not match the algorithm");
         }
     }
     m.Put(HashAlg, "HashAlg");
     m.Put(HashData, "HashData");
 }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:12,代码来源:TpmCustomDefs.cs

示例9: PolicyUpdate

 /// <summary>
 /// Return an updated policy hash according to the TPM specification.
 /// </summary>
 /// <param name="?"></param>
 /// <param name="currentHash"></param>
 /// <param name="commandCode"></param>
 /// <param name="name"></param>
 /// <param name="refData"></param>
 /// <returns></returns>
 internal TpmHash PolicyUpdate(TpmHash currentHash, TpmCc commandCode, byte[] name, byte[] refData)
 {
     var m = new Marshaller();
     m.Put(commandCode, "commandCode");
     m.Put(name, "name");
     TpmHash h1 = currentHash.Extend(m.GetBytes());
     TpmHash h2 = h1.Extend(refData);
     return h2;
 }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:18,代码来源:PolicyAces.cs

示例10: GetSelectionHash

 /// <summary>
 /// Get the hash of the concatenation of the values in the array order defined by the PcrSelection[] 
 /// returned from GetPcrSelectionArray.
 /// </summary>
 /// <param name="hashAlg"></param>
 /// <returns></returns>
 public TpmHash GetSelectionHash(TpmAlgId hashAlg)
 {
     var m = new Marshaller();
     PcrSelection[] selections = GetPcrSelectionArray();
     foreach (PcrSelection sel in selections)
     {
         uint[] pcrIndices = sel.GetSelectedPcrs();
         foreach (uint index in pcrIndices)
         {
             PcrValue v = GetSpecificValue(sel.hash, index);
             m.Put(v.value.HashData, "hash");
         }
     }
     var valueHash = new TpmHash(hashAlg, CryptoLib.HashData(hashAlg, m.GetBytes()));
     return valueHash;
 }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:22,代码来源:TpmCustomDefs.cs

示例11: Execute

        // ReSharper disable once InconsistentNaming
        internal override TpmRc Execute(Tpm2 tpm, AuthSession authSession, PolicyTree policy)
        {
            byte[] nonceTpm = UseNonceTpm ? Globs.CopyData(authSession.NonceTpm) : new byte[0];

            var dataToSign = new Marshaller();
            dataToSign.Put(nonceTpm, "");
            ISignatureUnion signature;
            // If the library has been given a signing key we can do the challenge here (else we need to call out)
            TpmHandle verificationKey;
            if (SigningKey != null)
            {
                dataToSign.Put(ExpirationTime, "");
                dataToSign.Put(CpHash, "");
                dataToSign.Put(PolicyRef, "");
                // Just ask the key to sign the challenge
                signature = SigningKey.Sign(dataToSign.GetBytes());
                verificationKey = tpm.LoadExternal(null, SigningKeyPub, TpmRh.Owner);
            }
            else
            {
                TpmPublic verifier;
                signature = AssociatedPolicy.ExecuteSignerCallback(this, nonceTpm, out verifier);
                verificationKey = tpm.LoadExternal(null, verifier, TpmRh.Owner);
            }
            TkAuth policyTicket;

            Timeout = tpm.PolicySigned(verificationKey,
                                       authSession,
                                       nonceTpm,
                                       CpHash,
                                       PolicyRef,
                                       ExpirationTime,
                                       signature,
                                       out policyTicket);

            TpmRc responseCode = tpm._GetLastResponseCode();
            // Save the policyTicket in case it is needed later
            PolicyTicket = policyTicket;
            tpm.FlushContext(verificationKey);
            return responseCode;
        }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:42,代码来源:PolicyAces.cs

示例12: PolicyUpdate1

        /// <summary>
        /// Implements the first step of the policy digest update (see the PolicyUpdate()
        /// method), and also used by PolicyAuthorizeNV.
        /// </summary>
        internal TpmHash PolicyUpdate1(TpmHash currentHash, TpmCc commandCode, byte[] name)
        {
            var m = new Marshaller();
            m.Put(commandCode, "commandCode");
            m.Put(name, "name");

            return currentHash.Extend(m.GetBytes());
        }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:12,代码来源:PolicyAces.cs

示例13: UpdateHandleData

        } // UpdateHandleData()

        /// <summary>
        /// Calculate the command hash.  Note that the handles are replaced by the name of the referenced object
        /// </summary>
        /// <param name="hashAlg"></param>
        /// <param name="commandParms"></param>
        /// <param name="handles"></param>
        /// <returns></returns>
        private byte[] GetCommandHash(TpmAlgId hashAlg, byte[] commandParms, TpmHandle[] handles)
        {
            var temp = new Marshaller();
            temp.Put(CurrentCommand, "ordinal");
            for (int j = 0; j < handles.Length; j++)
            {
                temp.Put(handles[j].Name, "name + " + j);
            }
            temp.Put(commandParms, "commandParms");
            byte[] parmsHash = CryptoLib.HashData(hashAlg, temp.GetBytes());
            return parmsHash;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:21,代码来源:Tpm2.cs

示例14: CreateCommand

        /// <summary>
        /// Create a TPM command byte stream from constituent components
        /// </summary>
        /// <param name="commandCode"></param>
        /// <param name="handles"></param>
        /// <param name="sessions"></param>
        /// <param name="parmsWithoutHandles"></param>
        /// <returns></returns>
        public static byte[] CreateCommand(
            TpmCc commandCode,
            TpmHandle[] handles,
            SessionIn[] sessions,
            byte[] parmsWithoutHandles)
        {

            // ReSharper disable once UnusedVariable
            CommandInfo commandInfo = Tpm2.CommandInfoFromCommandCode(commandCode);

            var m = new Marshaller();
            TpmSt tag = sessions.Length == 0 ? TpmSt.NoSessions : TpmSt.Sessions;
            m.Put(tag, "tag");
            m.PushLength(4);
            m.Put(commandCode, "commandCode");
            foreach (TpmHandle h in handles)
            {
                m.Put(h, "handle");
            }

            if (tag == TpmSt.Sessions)
            {
                var m2 = new Marshaller();
                foreach (SessionIn s in sessions)
                {
                    m2.Put(s, "session");
                }
                m.PutUintPrependedArray(m2.GetBytes(), "sessions");
            }

            m.Put(parmsWithoutHandles, "parms");

            m.PopAndSetLengthToTotalLength();
            return m.GetBytes();
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:43,代码来源:Tpm2.cs

示例15: ParseCommand

        public static string ParseCommand(byte[] buf)
        {
            CommandHeader commandHeader;
            TpmHandle[] inHandles;
            SessionIn[] inSessions;
            byte[] commandParmsNoHandles;
            string response = "";

            bool ok = CrackCommand(buf, out commandHeader, out inHandles, out inSessions, out commandParmsNoHandles);
            if (!ok)
            {
                response = "The TPM command is not properly formatted.  Doing the best I can...\n";
            }
            CommandInfo command = Tpm2.CommandInfoFromCommandCode(commandHeader.CommandCode);
            if (command == null)
            {
                response += String.Format("The command-code {0} is not defined.  Aborting\n", commandHeader.CommandCode);
                return response;
            }
            response += "Header:\n";
            response += commandHeader + "\n";

            var m2 = new Marshaller();
            foreach (TpmHandle h in inHandles)
            {
                m2.Put(h, "");
            }

            byte[] commandParmsWithHandles = Globs.Concatenate(new[] {m2.GetBytes(), commandParmsNoHandles});
            var m = new Marshaller(commandParmsWithHandles);
            object inParms = m.Get(command.InStructType, "");
            response += "Command Parameters:\n";
            response += inParms + "\n";
            response += "Sessions [" + inSessions.Length + "]\n";
            for (int j = 0; j < inSessions.Length; j++)
            {
                // ReSharper disable once FormatStringProblem
                response += String.Format("{0}: 0x{1:x}\n", j, inSessions[j]);
            }
            return response;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:41,代码来源:Tpm2.cs


注:本文中的Marshaller.Put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。