var base64OwnerToken = make([]byte, 24)
base64.RawURLEncoding.Encode(base64OwnerToken, storedPaste.OwnerToken[:])
In https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/handlers.go#L56 we can use `base64.RawURLEncoding` provided in the standard library.
E.g. https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/handlers.go#L251
```
var base64OwnerToken = make([]byte, 24)
base64.RawURLEncoding.Encode(base64OwnerToken, storedPaste.OwnerToken[:])
```
I am wondering if this is actually possible. Although we use the base64url alphabet, we do not use the base64 encoding. That is, because our IDs are generated in base 64, not in base 256. (I.e. they are not defined over bytes, but over sextets.)
Reusing base64.encodeURL, would be cool, but is obviously impossible.
Closing this as wontfix.
I am wondering if this is actually possible. Although we use the base64url *alphabet*, we do not use the base64 *encoding*. That is, because our IDs are generated in base 64, not in base *256*. (I.e. they are not defined over bytes, but over sextets.)
Reusing [`base64.encodeURL`](https://golang.org/src/encoding/base64/base64.go?s=14692:14745#L36), would be cool, but is obviously impossible.
Closing this as wontfix.
That is, because our IDs are generated in base 64, not in base 256.
because that is (obviously) not the case.
In https://gitea.hashru.nl/dsprenkels/rushlink/src/commit/544c093c353257bc67395e2a085f1c20318a182c/internal/handlers/handlers.go#L257 you do a base64 encoding over a slice of bytes, that seem ultimately filled through `generateOwnerToken()` in https://gitea.hashru.nl/dsprenkels/rushlink/src/commit/544c093c353257bc67395e2a085f1c20318a182c/internal/handlers/handlers.go#L373, where 16 bytes are sourced from `rand.Read()`.
I'm not sure what you mean with
> That is, because our IDs are generated in base 64, not in base 256.
because that is (_obviously_) not the case.
I now see what you mean. I fixed this; applying this patch:
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index 39077ac..a4a0a87 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -56,7 +56,7 @@ var ReservedPasteKeys [][]byte = [][]byte{[]byte("xd42"), []byte("example")}
// Base64 encoding and decoding
var base64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
-var base64Encoder = base64.NewEncoding(base64Alphabet).WithPadding(base64.NoPadding)
+var base64Encoder = base64.RawURLEncoding.WithPadding(base64.NoPadding)
// Page contents
var baseTemplate = template.New("empty")
I now see what you mean. I fixed this; applying this patch:
```diff
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index 39077ac..a4a0a87 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -56,7 +56,7 @@ var ReservedPasteKeys [][]byte = [][]byte{[]byte("xd42"), []byte("example")}
// Base64 encoding and decoding
var base64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
-var base64Encoder = base64.NewEncoding(base64Alphabet).WithPadding(base64.NoPadding)
+var base64Encoder = base64.RawURLEncoding.WithPadding(base64.NoPadding)
// Page contents
var baseTemplate = template.New("empty")
```
Note. It seems I misunderstood which base64 encoding was meant, because of the outdated line specifiers. I should just have Ctrl+F'd the code in the snippet.
Note. It seems I misunderstood which base64 encoding was meant, because of the outdated line specifiers. I should just have Ctrl+F'd the code in the snippet.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
In https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/handlers.go#L56 we can use
base64.RawURLEncodingprovided in the standard library.E.g. https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/handlers.go#L251
I am wondering if this is actually possible. Although we use the base64url alphabet, we do not use the base64 encoding. That is, because our IDs are generated in base 64, not in base 256. (I.e. they are not defined over bytes, but over sextets.)
Reusing
base64.encodeURL, would be cool, but is obviously impossible.Closing this as wontfix.
In
544c093c35/internal/handlers/handlers.go (L257)you do a base64 encoding over a slice of bytes, that seem ultimately filled throughgenerateOwnerToken()in544c093c35/internal/handlers/handlers.go (L373), where 16 bytes are sourced fromrand.Read().I'm not sure what you mean with
because that is (obviously) not the case.
I now see what you mean. I fixed this; applying this patch:
Note. It seems I misunderstood which base64 encoding was meant, because of the outdated line specifiers. I should just have Ctrl+F'd the code in the snippet.