// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.TokenFactoryCredential
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 516D8B44-4448-4D2C-8B8E-FFBB3FFE472B
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Virus.Win32.Expiro.w-69bb73081eac86b8cf86f45e33515d0095855636967076e2b593d7a30cd80a07.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.IO;

namespace Microsoft.InfoCards
{
  internal abstract class TokenFactoryCredential : IDisposable
  {
    public const int NoCredential = -1;
    private TokenFactoryCredentialType m_type;
    private Uri m_cardId;
    private int m_paramIndex;
    private int m_lcid;

    protected TokenFactoryCredential(TokenFactoryCredentialType type) => this.m_type = type;

    public void Dispose() => this.Dispose(true);

    public virtual void Dispose(bool disposing)
    {
    }

    public static TokenFactoryCredential CreateFrom(
      BinaryReader reader,
      UIAgentRequest request,
      int lcid)
    {
      TokenFactoryCredential from;
      switch (reader.ReadInt32())
      {
        case -1:
          from = (TokenFactoryCredential) null;
          break;
        case 1:
          from = (TokenFactoryCredential) new UserNameTokenFactoryCredential();
          from.Deserialize(reader);
          break;
        case 2:
          from = (TokenFactoryCredential) new SelfIssuedTokenFactoryCredential();
          from.Deserialize(reader);
          break;
        case 3:
          from = (TokenFactoryCredential) new X509CertificateTokenFactoryCredential(request);
          from.Deserialize(reader);
          break;
        case 4:
          from = (TokenFactoryCredential) new KerberosTokenFactoryCredential();
          from.Deserialize(reader);
          break;
        default:
          InfoCardTrace.ThrowInvalidArgumentConditional(true, "CredentialType");
          from = (TokenFactoryCredential) null;
          break;
      }
      if (from != null)
        from.LCID = lcid;
      return from;
    }

    public int ParameterIndex => this.m_paramIndex;

    public TokenFactoryCredentialType CredentialType => this.m_type;

    public int LCID
    {
      get => this.m_lcid;
      set => this.m_lcid = value;
    }

    public Uri CardId => this.m_cardId;

    private void Deserialize(BinaryReader reader)
    {
      this.m_cardId = new Uri(Utility.DeserializeString(reader));
      this.m_paramIndex = reader.ReadInt32();
      this.DeserializeData(reader);
    }

    protected abstract void DeserializeData(BinaryReader reader);
  }
}