Skip to content

Commit

Permalink
Add GetPrimaryKey Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtule committed Aug 9, 2017
1 parent d42da57 commit ea327e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Keyczar/Keyczar/KeySet/IKeySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public static Key GetKey(this IKeySet keySet, int version)
return key;
}

private static Key GetPrimaryKey(this IKeySet keySet)
{
var version = keySet.Metadata.GetPrimaryKeyVersion();
return version == null
? null
: keySet.GetKey(version.VersionNumber);
}

public static KeyVersion GetPrimaryKeyVersion(this KeyMetadata metadata)
{
return metadata.Versions.SingleOrDefault(it => it.Status == KeyStatus.Primary);
}

public static KeyczarConfig GetConfig(this IKeySet keySet)
{
return keySet.Config ?? KeyczarDefaults.DefaultConfig;
Expand Down
2 changes: 1 addition & 1 deletion Keyczar/Keyczar/KeyczarBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected KeyczarBase(IKeySet keySet)
})
.ToList();

_primaryVersion = metadata.Versions.SingleOrDefault(it => it.Status == KeyStatus.Primary);
_primaryVersion = metadata.GetPrimaryKeyVersion();

_versions = versions.ToDictionary(k => k.Item2.VersionNumber, v => v.Item3);

Expand Down

0 comments on commit ea327e7

Please sign in to comment.