2024-03-12 20:59:07 +01:00
|
|
|
// SPDX-FileCopyrightText: 2021-2024 Winni Neessen <wn@neessen.dev>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2023-08-04 16:02:58 +02:00
|
|
|
package apg
|
|
|
|
|
|
|
|
// Algorithm is a type wrapper for an int type to represent different
|
|
|
|
// password generation algorithm
|
|
|
|
type Algorithm int
|
|
|
|
|
|
|
|
const (
|
2024-03-12 18:28:01 +01:00
|
|
|
// AlgoPronounceable represents the algorithm for pronounceable passwords
|
2023-08-04 16:02:58 +02:00
|
|
|
// (koremutake syllables)
|
2024-03-12 18:28:01 +01:00
|
|
|
AlgoPronounceable Algorithm = iota
|
2023-08-04 20:35:31 +02:00
|
|
|
// AlgoRandom represents the algorithm for purely random passwords according
|
2023-08-04 16:02:58 +02:00
|
|
|
// to the provided password modes/flags
|
2023-08-04 20:35:31 +02:00
|
|
|
AlgoRandom
|
2023-08-05 18:10:11 +02:00
|
|
|
// AlgoCoinFlip represents a very simple coinflip algorithm returning "heads"
|
|
|
|
// or "tails"
|
|
|
|
AlgoCoinFlip
|
2024-03-17 18:09:27 +01:00
|
|
|
// AlgoBinary represents a full binary randomness mode with up to 256 bits
|
|
|
|
// of randomness
|
|
|
|
AlgoBinary
|
2023-08-04 20:35:31 +02:00
|
|
|
// AlgoUnsupported represents an unsupported algorithm
|
|
|
|
AlgoUnsupported
|
2023-08-04 16:02:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// IntToAlgo takes an int value as input and returns the corresponding
|
|
|
|
// Algorithm
|
|
|
|
func IntToAlgo(a int) Algorithm {
|
|
|
|
switch a {
|
|
|
|
case 0:
|
2024-03-12 18:28:01 +01:00
|
|
|
return AlgoPronounceable
|
2023-08-04 16:02:58 +02:00
|
|
|
case 1:
|
2023-08-04 20:35:31 +02:00
|
|
|
return AlgoRandom
|
2023-08-05 18:10:11 +02:00
|
|
|
case 2:
|
|
|
|
return AlgoCoinFlip
|
2024-03-17 18:09:27 +01:00
|
|
|
case 3:
|
|
|
|
return AlgoBinary
|
2023-08-04 16:02:58 +02:00
|
|
|
default:
|
2023-08-04 20:35:31 +02:00
|
|
|
return AlgoUnsupported
|
2023-08-04 16:02:58 +02:00
|
|
|
}
|
|
|
|
}
|