Skip to main content
Table of Contents

Struct KeySubject

Namespace
Stratara.Abstractions.Security
Assembly
Stratara.Abstractions.dll

A tenant or a user whose erasure a key store records, so that it creates no key for the subject afterwards. Covers(KeyScope) decides which scopes that is — the same keys the subject's erasure shreds.

public readonly record struct KeySubject : IEquatable<KeySubject>
Implements
Inherited Members
Extension Methods

Remarks

Two subjects are equal when their kind matches and their ids match without regard to case, the same comparison Covers(KeyScope) uses, so a set of subjects holds each one once.

Properties

Id

The subject's id, as it appears in a KeyScope; empty on the default value, which names no subject.

public string Id { get; }

Property Value

string

Kind

Whether the subject is a tenant or a user.

public KeySubjectKind Kind { get; }

Property Value

KeySubjectKind

Methods

Covers(KeyScope)

Whether the subject's erasure covers a scope: for a tenant, a scope of any level that names the tenant; for a user, a UserScoped scope that names the user, and a scope of any level that names the user and no tenant of theirs — no tenant, or the reserved default tenant (Empty) under which data owned by the user alone is written. Ids compare without regard to case, so a GUID written in either case is matched. The default value names no subject and covers nothing.

public bool Covers(KeyScope scope)

Parameters

scope KeyScope

The scope to test.

Returns

bool

true when the scope belongs to the subject's erasure.

Equals(KeySubject)

Whether both name the same subject: the same kind, and ids equal without regard to case.

public bool Equals(KeySubject other)

Parameters

other KeySubject

The subject to compare with.

Returns

bool

true when both name the same subject.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Tenant(string)

Names a tenant.

public static KeySubject Tenant(string tenantId)

Parameters

tenantId string

The tenant id, as TenantId carries it.

Returns

KeySubject

The tenant subject.

Exceptions

ArgumentException

tenantId is empty or white space.

ArgumentNullException

tenantId is null.

ThrowIfDefault(string)

Throws when the value is the default one, which names no subject.

public void ThrowIfDefault(string paramName)

Parameters

paramName string

The name of the parameter that carried the subject.

Exceptions

ArgumentException

The subject was not created through Tenant(string) or User(string).

User(string)

Names a user.

public static KeySubject User(string userId)

Parameters

userId string

The user id, as UserId carries it.

Returns

KeySubject

The user subject.

Exceptions

ArgumentException

userId is empty or white space.

ArgumentNullException

userId is null.