common/keys.aug
OpenID Connect login application · Source and specification
Files in this project
main.augclient/contracts.augclient/endpoints.augclient/export.augclient/login.augclient/logout.augclient/protocol.augclient/session.augclient/views.augcommon/export.augcommon/headers.augcommon/keys.augcommon/settings.augcommon/views.augprovider/authorization.augprovider/contracts.augprovider/credentials.augprovider/discovery.augprovider/export.augprovider/token.augprovider/userinfo.augprovider/views.aug
Code
// aug-spec: "keys.aug.md" explains this file. Read it before changes; refresh with aug spec.
import Crypto from crypto
KeyError() implements Error:
pass
/** Keys are initialized explicitly in main and expose distinct provider and session roles. */
capability SigningKeys:
configure(RsaPrivateKey provider, RsaPrivateKey session) uses SigningKeys.configure unless KeyError
provider() returns RsaPrivateKey uses SigningKeys.provider unless KeyError
session() returns RsaPrivateKey uses SigningKeys.session unless KeyError
MemorySigningKeys() implements SigningKeys:
Shared<Map<string,RsaPrivateKey>> _keys = Shared(value=Map<string, RsaPrivateKey>())
configure(RsaPrivateKey provider, RsaPrivateKey session):
lock _keys as keys:
if keys.length() != 0:
throw KeyError()
keys.set(key="provider", value=provider)
keys.set(key="session", value=session)
provider():
lock _keys as keys:
match keys.get(key="provider"):
when null:
throw KeyError()
when some key:
return key
session():
lock _keys as keys:
match keys.get(key="session"):
when null:
throw KeyError()
when some key:
return key
initializeKeys(resolve Crypto crypto, resolve SigningKeys keys):
provider = crypto.generateRsa()
session = crypto.generateRsa()
keys.configure(provider, session)// aug-spec: "keys.aug.md" explains this file. Read it before changes; refresh with aug spec.
import Crypto from crypto
KeyError() implements Error {
pass
}
/** Keys are initialized explicitly in main and expose distinct provider and session roles. */
capability SigningKeys {
configure(RsaPrivateKey provider, RsaPrivateKey session) uses SigningKeys.configure unless KeyError
provider() returns RsaPrivateKey uses SigningKeys.provider unless KeyError
session() returns RsaPrivateKey uses SigningKeys.session unless KeyError
}
MemorySigningKeys() implements SigningKeys {
Shared<Map<string,RsaPrivateKey>> _keys = Shared(value=Map<string, RsaPrivateKey>())
configure(RsaPrivateKey provider, RsaPrivateKey session) {
lock _keys as keys {
if keys.length() != 0 {
throw KeyError()
}
keys.set(key="provider", value=provider)
keys.set(key="session", value=session)
}
}
provider() {
lock _keys as keys {
match keys.get(key="provider") {
when null {
throw KeyError()
}
when some key {
return key
}
}
}
}
session() {
lock _keys as keys {
match keys.get(key="session") {
when null {
throw KeyError()
}
when some key {
return key
}
}
}
}
}
initializeKeys(resolve Crypto crypto, resolve SigningKeys keys) {
provider = crypto.generateRsa()
session = crypto.generateRsa()
keys.configure(provider, session)
}Compiled specification
KeyError · class · source
It implements Error.
SigningKeys · capability interface · source
Keys are initialized explicitly in main and expose distinct provider and session roles.
SigningKeys.configure · source
It takes provider and session as RsaPrivateKey. It can call SigningKeys.configure. Failures can raise KeyError.
SigningKeys.provider · source
It returns RsaPrivateKey. It can call SigningKeys.provider. Failures can raise KeyError.
SigningKeys.session · source
It returns RsaPrivateKey. It can call SigningKeys.session. Failures can raise KeyError.
MemorySigningKeys · class · source
It implements SigningKeys. The read-only, private field _keys has type Shared<Map<string,RsaPrivateKey>> and starts as a Shared with value from an empty map from string to RsaPrivateKey.
MemorySigningKeys.configure · source
It takes provider and session as RsaPrivateKey. It can call SigningKeys.configure. Failures can raise KeyError.
While holding the lock on _keys as mutable keys, it checks that the number of elements in keys equals 0. It raises a KeyError at the first failed check. It stores provider in keys under "provider". It stores session in keys under "session". source
Release this lock when the block exits, including on return or failure. source
Checked interface
configure(RsaPrivateKey provider, RsaPrivateKey session) returns void unless KeyError uses SigningKeys.configureIt takes provider and session as RsaPrivateKey. It can call SigningKeys.configure. Failures can raise KeyError.
MemorySigningKeys.provider · source
It can call SigningKeys.provider. Failures can raise KeyError.
While holding the lock on _keys as mutable keys, it obtains the value under "provider" in keys. If no value is found, it raises a KeyError. The non-null result becomes key. It returns key. source
Release this lock when the block exits, including on return or failure. source
Checked interface
provider() returns RsaPrivateKey unless KeyError uses SigningKeys.providerIt can call SigningKeys.provider. Failures can raise KeyError.
MemorySigningKeys.session · source
It can call SigningKeys.session. Failures can raise KeyError.
While holding the lock on _keys as mutable keys, it obtains the value under "session" in keys. If no value is found, it raises a KeyError. The non-null result becomes key. It returns key. source
Release this lock when the block exits, including on return or failure. source
Checked interface
session() returns RsaPrivateKey unless KeyError uses SigningKeys.sessionIt can call SigningKeys.session. Failures can raise KeyError.
initializeKeys · source
It gets crypto (Crypto) and keys (SigningKeys) from dependency injection. It can call Crypto.generateRsa and SigningKeys.configure. Failures can raise CryptoError and KeyError.
It sets provider and session separately, each to crypto.generateRsa. It calls keys.configure with provider and session. source
Checked interface
initializeKeys(resolve Crypto crypto, resolve SigningKeys keys) returns void unless CryptoError and KeyError uses Crypto.generateRsa, SigningKeys.configureIt gets crypto (Crypto) and keys (SigningKeys) from dependency injection. It can call Crypto.generateRsa and SigningKeys.configure. Failures can raise CryptoError and KeyError.
Dependencies
It uses Crypto (generateRsa) from crypto.
Built-in operations follow the language reference.