Skip to content

Commit

Permalink
Merge pull request #26 from marcelkliemannel/develop
Browse files Browse the repository at this point in the history
2.4.1
  • Loading branch information
marcelkliemannel authored Apr 15, 2024
2 parents 946719e + f56bcc8 commit d2c48f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ The implementations are based on the RFCs:
* [RFC 4226: "RFC 4226 HOTP: An HMAC-Based One-Time Password Algorithm"](https://www.ietf.org/rfc/rfc4226.txt)
* [RFC 6238: "TOTP: Time-Based One-Time Password Algorithm"](https://tools.ietf.org/html/rfc6238)

> ℹ️ In this repository, changes don't happen that often and the library gets updated very rarely. However, this is **not** an abandoned project. Since the code is relatively simple, follows the specifications of the two RFCs, and has good test coverage, there is hardly any need to change anything.
> [!NOTE]
> This library is updated very rarely, and there are only minor changes every now and then. However, this should not be seen as an abandonment of the project. Since the code is relatively simple, follows the specifications of the relevant RFCs, and has good test coverage, there is little need to change anything.
> ℹ️ If you want to use this library in conjunction with the Google Authenticator app (or similar apps), please carefully read the chapter [Google Authenticator](#google-authenticator), especially the remarks regarding the Base32-encoded secret and the plain text secret length limitation. Most problems arise from not following the two remarks correctly.
> [!TIP]
> If you want to use this library in conjunction with the Google Authenticator app (or similar apps), please carefully read the chapter [Google Authenticator](#google-authenticator), especially the remarks regarding the Base32-encoded secret and the plain text secret length limitation. Most problems arise from not following the two remarks correctly.
>
> This library gets used by hundreds of active users every day to generate Google Authenticator codes for several years now, so I am very confident that the code correctly generates codes.
Expand Down Expand Up @@ -44,10 +46,10 @@ This library is available at [Maven Central](https://mvnrepository.com/artifact/

```java
// Groovy
implementation 'dev.turingcomplete:kotlin-onetimepassword:2.4.0'
implementation 'dev.turingcomplete:kotlin-onetimepassword:2.4.1'

// Kotlin
implementation("dev.turingcomplete:kotlin-onetimepassword:2.4.0")
implementation("dev.turingcomplete:kotlin-onetimepassword:2.4.1")
```

### Maven
Expand All @@ -56,7 +58,7 @@ implementation("dev.turingcomplete:kotlin-onetimepassword:2.4.0")
<dependency>
<groupId>dev.turingcomplete</groupId>
<artifactId>kotlin-onetimepassword</artifactId>
<version>2.4.0</version>
<version>2.4.1</version>
</dependency>
```

Expand Down Expand Up @@ -268,7 +270,7 @@ Note that according to the specification, the Base32 padding character `=` will

## Licensing

Copyright (c) 2023 Marcel Kliemannel
Copyright (c) 2024 Marcel Kliemannel

Licensed under the **Apache License, Version 2.0** (the "License"); you may not use this file except in compliance with the License.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

allprojects {
group = "dev.turingcomplete"
version = "2.4.0"
version = "2.4.1"

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ open class OtpAuthUriBuilder<S : OtpAuthUriBuilder<S>>(private val type: String,

private fun buildUriWithoutSecret(additionalParameters: Map<String, String> = emptyMap()): String {
val query = parameters.plus(additionalParameters).map { "${it.key}=${it.value}" }.joinToString(separator = "&", prefix = "?")
return "otpauth://$type/${if (label != null) "$label/" else ""}$query"
return "otpauth://$type/${if (label != null) label else ""}$query"
}

private fun removePaddingFromBase32Secret(base32Secret: ByteArray): ByteArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,25 @@ class OtpAuthUriBuilderTest {

@Test
fun testLabel() {
assertEquals("otpauth://totp/iss:acc/?secret=$BASE32_SECRET_REMOVED_PADDING",
assertEquals("otpauth://totp/iss:acc?secret=$BASE32_SECRET_REMOVED_PADDING",
OtpAuthUriBuilder.forTotp(BASE32_SECRET)
.label("acc", "iss", false)
.buildToString())

assertEquals("otpauth://totp/acc/?secret=$BASE32_SECRET_REMOVED_PADDING",
assertEquals("otpauth://totp/acc?secret=$BASE32_SECRET_REMOVED_PADDING",
OtpAuthUriBuilder.forTotp(BASE32_SECRET)
.label("acc", null, false)
.buildToString())

assertEquals("otpauth://totp/iss%3Aacc/?secret=$BASE32_SECRET_REMOVED_PADDING",
assertEquals("otpauth://totp/iss%3Aacc?secret=$BASE32_SECRET_REMOVED_PADDING",
OtpAuthUriBuilder.forTotp(BASE32_SECRET)
.label("acc", "iss", true)
.buildToString())
}

@Test
fun testLabelUrlEncoding() {
assertEquals("otpauth://totp/i%2F%2Fss%3Aa%2F%2Fcc/?secret=$BASE32_SECRET_REMOVED_PADDING",
assertEquals("otpauth://totp/i%2F%2Fss%3Aa%2F%2Fcc?secret=$BASE32_SECRET_REMOVED_PADDING",
OtpAuthUriBuilder.forTotp(BASE32_SECRET)
.label("a//cc", "i//ss", true)
.buildToString())
Expand All @@ -121,7 +121,7 @@ class OtpAuthUriBuilderTest {
.digits(8)

val stringRepresentation = builder.buildToString()
assertEquals("otpauth://totp/i%2Fss:acc/?issuer=i%2Fss&digits=8&secret=$BASE32_SECRET_REMOVED_PADDING", stringRepresentation)
assertEquals("otpauth://totp/i%2Fss:acc?issuer=i%2Fss&digits=8&secret=$BASE32_SECRET_REMOVED_PADDING", stringRepresentation)

val byteArrayRepresentation = builder.buildToByteArray()
assertEquals(stringRepresentation, String(byteArrayRepresentation))
Expand Down

0 comments on commit d2c48f3

Please sign in to comment.