pvfr.passeport_credential package

Module contents

Library for generating verifiable credentials for the Passeport vacances Fribourg

This library is used to generate verifiable serial numbers or verifiable passwords for the Passeport vacances Fribourg. It is also used to check if a serial number or a password is valid.

Typical usage example:

from pvfr.passeport_credential import Signer, SerialNumber, Password

s = Signer("f09d837b265d7ff95d724c7f9dcc8b51dc6a357db5630eedff48b6c1659e2181")

serialGen = SerialNumber(s)
print(serialGen.serial(0))
print(serialGen.check("000100994252"))

pwGen = Password(s)
print(pwGen.password(0))
print(pwGen.check(0,"yd2f-ktfb-dyru"))
class pvfr.passeport_credential.Credential(signer: pvfr.passeport_credential.Signer)[source]

Bases: object

The Credential is the base class for SerialNumber and Password

__init__(signer: pvfr.passeport_credential.Signer)[source]

Initialize the credential with a signer.

Parameters:signer (Signer) – The signer associated with the credential.
signature(number: int) → int[source]

Generate a signature.

Parameters:number (int) – The number to sign.
Returns:The signature.
Return type:int
class pvfr.passeport_credential.Password(signer: pvfr.passeport_credential.Signer, blocks: int = 3, size: int = 4)[source]

Bases: pvfr.passeport_credential.Credential

Class to generate and verify Passwords

The passwords are composed of blocks of digits and lettres, excluding the characters that can easily be mistaken (such as 0 and O or 1 and l).

__init__(signer: pvfr.passeport_credential.Signer, blocks: int = 3, size: int = 4)[source]

Initialize the password

Parameters:
  • signer (Signer) – The signer associated with the credential.
  • blocks (int) – The number of blocks composing the password.
  • size (int) – The size (length) of each blocks.
check(number: int, passwd: str) → bool[source]

Check a password

Parameters:
  • number (int) – The number from the username.
  • passwd (str) – The password to check.
Returns:

True if the password is valid for the number.

Return type:

bool

password(number: int) → str[source]

Generate a password for number

Parameters:number (int) – The number to generate a password for.
Returns:The password.
Return type:str
class pvfr.passeport_credential.SerialNumber(signer: pvfr.passeport_credential.Signer, size: int = 8)[source]

Bases: pvfr.passeport_credential.Credential

Class to generate and verify Serial Numbers

__init__(signer: pvfr.passeport_credential.Signer, size: int = 8)[source]

Initialize the serial number

Parameters:
  • signer (Signer) – The signer associated with the credential.
  • size (int) – The size (length) of the serial number.
check(ser: str) → bool[source]

Check a serial number

Parameters:ser (str) – The serial number to check.
Returns:True if the serial number is valid.
Return type:bool
serial(number: int) → str[source]

Generate a serial number for number

Parameters:number (int) – The number to generate a serial number for.
Returns:The serial number.
Return type:str
class pvfr.passeport_credential.Signer(key: str, length: int = 4)[source]

Bases: object

The Signer is able to produce a HMAC signature, based on a secret key, for an integer

__init__(key: str, length: int = 4)[source]

Initialize the signer with the given key.

Parameters:
  • key (str) – The signing key.
  • len (int) – The maximum number of digits of the number to sign.
signature(number: int) → int[source]

Sign the number.

Parameters:number (int) – The number to sign.
Returns:The signature.
Return type:int