Skip to content

simpleotp.otpconfig

Eugene Fox edited this page Sep 18, 2024 · 1 revision

OtpConfig

Namespace: SimpleOTP

Represents the configuration for a One-Time Password (OTP).

public class OtpConfig : System.Xml.Serialization.IXmlSerializable, System.IEquatable`1[[SimpleOTP.OtpConfig, SimpleOTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]]

Inheritance ObjectOtpConfig
Implements IXmlSerializable, IEquatable<OtpConfig>
Attributes SerializableAttribute, NullableContextAttribute, NullableAttribute, JsonConverterAttribute

Properties

EqualityContract

protected Type EqualityContract { get; }

Property Value

Type

Type

Gets or sets the type of the OTP.

public OtpType Type { get; set; }

Property Value

OtpType
Default is: OtpType.Totp

Remarks:

Internet-Draft.
IMPORTANT: Some authenticators do not support OtpType.Hotp.

IssuerLabel

Gets or sets the issuer label prefix of the OTP.

public string IssuerLabel { get; set; }

Property Value

String

Remarks:

Internet-Draft.

Label

Gets or sets the label of the OTP.

public string Label { get; set; }

Property Value

String

Remarks:

Internet-Draft.

Secret

Gets or sets the secret of the OTP.

public OtpSecret Secret { get; set; }

Property Value

OtpSecret
Default: 160-bit key. Minimal recommended: 128 bits

Remarks:

Internet-Draft

Algorithm

Gets or sets the hashing algorithm of the OTP.

public OtpAlgorithm Algorithm { get; set; }

Property Value

OtpAlgorithm
Default: OtpAlgorithm.SHA1

Remarks:

Internet-Draft
IMPORTANT: Some authenticators do not support algorithms other than OtpAlgorithm.SHA1.

Issuer

Gets or sets the issuer of the OTP. Optional.

public string Issuer { get; set; }

Property Value

String

Remarks:

Internet-Draft

Digits

Gets or sets the number of digits of the OTP codes.

public int Digits { get; set; }

Property Value

Int32
Default: 6. Recommended: 6 or 8

Remarks:

Internet-Draft
IMPORTANT: Some authenticators do not support digits other than 6.

Counter

Gets or sets the counter of the OTP. Required for OtpType.Hotp. Ignored for OtpType.Totp.

public long Counter { get; set; }

Property Value

Int64
Default: 0

Remarks:

Internet-Draft
IMPORTANT: Some authenticators do not support OtpType.Hotp.

Period

Gets or sets the period of the OTP in seconds. Optional for OtpType.Totp. Ignored for OtpType.Hotp.

public int Period { get; set; }

Property Value

Int32
Default: 30

Remarks:

Internet-Draft
IMPORTANT: Some authenticators support only periods of 30 seconds.

CustomProperties

Gets the custom vendor-specified properties of the current OTP configuration.

public NameValueCollection CustomProperties { get; }

Property Value

NameValueCollection

Remarks:

If set, reserved keys issuer, digits, counter, secret, period and algorithm will be removed from the OtpConfig.CustomProperties upon it's serialization to URI.
Internet-Draft

Constructors

OtpConfig(String)

Initializes a new instance of the OtpConfig class.

public OtpConfig(string label)

Parameters

label String
The label of the OTP config.

OtpConfig(String, String)

Initializes a new instance of the OtpConfig class.

public OtpConfig(string label, string issuer)

Parameters

label String
The label of the OTP config.

issuer String
The issuer of the OTP config.

OtpConfig(String, OtpSecret)

Initializes a new instance of the OtpConfig class.

public OtpConfig(string label, OtpSecret secret)

Parameters

label String
The label of the OTP config.

secret OtpSecret
The secret of the OTP config.

OtpConfig(String, String, OtpSecret)

Initializes a new instance of the OtpConfig class.

public OtpConfig(string label, string issuer, OtpSecret secret)

Parameters

label String
The label of the OTP config.

issuer String
The issuer of the OTP config.

secret OtpSecret
The secret of the OTP config.

OtpConfig(Uri)

Initializes a new instance of the OtpConfig class.

public OtpConfig(Uri uri)

Parameters

uri Uri
The URI of the OTP config.

Exceptions

ArgumentException
Provided URI is not valid (missing required values or has invalid required values).

OtpConfig(Uri, IEncoder)

Initializes a new instance of the OtpConfig class.

public OtpConfig(Uri uri, IEncoder encoder)

Parameters

uri Uri
The URI of the OTP config.

encoder IEncoder
The encoder used to decode the secret.

Exceptions

ArgumentException
Provided URI is not valid (missing required values or has invalid required values).

OtpConfig(OtpConfig)

protected OtpConfig(OtpConfig original)

Parameters

original OtpConfig

Methods

ToUri()

Converts the current OtpConfig object to a object.

public Uri ToUri()

Returns

Uri
A object representing the current OtpConfig object.

Remarks:

Uses minimal Google specified formatting (OtpUriFormat.Minimal | OtpUriFormat.Google).

ToUri(OtpUriFormat)

Converts the current OtpConfig object to a object.

public Uri ToUri(OtpUriFormat format)

Parameters

format OtpUriFormat
A bitwise combination of the enumeration values that specifies the format of the URI.

Returns

Uri
A object representing the current OtpConfig object.

IsValid(String&, OtpUriFormat)

Returns if the specified OtpConfig object is valid.

public void IsValid(String& error, OtpUriFormat format)

Parameters

error String&
The error message returned if the OtpConfig object is invalid.

format OtpUriFormat
The OtpUriFormat to use for validation.

ToString()

public string ToString()

Returns

String

GetSchema()

public XmlSchema GetSchema()

Returns

XmlSchema

ReadXml(XmlReader)

public void ReadXml(XmlReader reader)

Parameters

reader XmlReader

WriteXml(XmlWriter)

public void WriteXml(XmlWriter writer)

Parameters

writer XmlWriter

ParseUri(Uri)

Parses the specified URI into an OtpConfig object.

public static OtpConfig ParseUri(Uri uri)

Parameters

uri Uri
The URI to parse.

Returns

OtpConfig
An OtpConfig object parsed from the specified URI.

Exceptions

ArgumentException
Provided URI is not valid (missing required values or has invalid required values).

ParseUri(Uri, IEncoder)

Initializes a new instance of the OtpConfig class.

public static OtpConfig ParseUri(Uri uri, IEncoder encoder)

Parameters

uri Uri
The URI of the OTP.

encoder IEncoder
The encoder used to decode the secret.

Returns

OtpConfig

Exceptions

ArgumentException
Provided URI is not valid (missing required values or has invalid required values).

ParseUri(String)

Parses the specified URI into an OtpConfig object.

public static OtpConfig ParseUri(string uri)

Parameters

uri String
The URI to parse.

Returns

OtpConfig
An OtpConfig object parsed from the specified URI.

Exceptions

ArgumentException
Provided URI is not valid (missing required values or has invalid required values).

T:System.UriFormatException
Provided URI is not valid (missing required values or has invalid required values).

TryParseUri(Uri, OtpConfig&)

Tries to parse the specified URI into an OtpConfig object.

public static bool TryParseUri(Uri uri, OtpConfig& config)

Parameters

uri Uri
The URI to parse.

config OtpConfig&
When this method returns, contains the OtpConfig object parsed from the specified URI, if the conversion succeeded, or null if the conversion failed.

Returns

Boolean
true if the conversion succeeded; otherwise, false.

TryParseUri(String, OtpConfig&)

Tries to parse the specified URI into an OtpConfig object.

public static bool TryParseUri(string uri, OtpConfig& config)

Parameters

uri String
The URI to parse.

config OtpConfig&
When this method returns, contains the OtpConfig object parsed from the specified URI, if the conversion succeeded, or null if the conversion failed.

Returns

Boolean
true if the conversion succeeded; otherwise, false.

Validate(OtpConfig, String&, OtpUriFormat)

Returns if the specified OtpConfig object is valid.

public static bool Validate(OtpConfig config, String& error, OtpUriFormat format)

Parameters

config OtpConfig
The OtpConfig object to validate.

error String&
The error message returned if the OtpConfig object is invalid.

format OtpUriFormat
The OtpUriFormat to use for validation.

Returns

Boolean
true if the conversion succeeded; otherwise, false.

Remarks:

The format should contain at least one vendor-specific format.

PrintMembers(StringBuilder)

protected bool PrintMembers(StringBuilder builder)

Parameters

builder StringBuilder

Returns

Boolean

GetHashCode()

public int GetHashCode()

Returns

Int32

Equals(Object)

public bool Equals(object obj)

Parameters

obj Object

Returns

Boolean

Equals(OtpConfig)

public bool Equals(OtpConfig other)

Parameters

other OtpConfig

Returns

Boolean

<Clone>$()

public OtpConfig <Clone>$()

Returns

OtpConfig

Clone this wiki locally