Comments (3)
Thanks for the report! I'll take a look at this, but it might be a few days, as I'll be out of town on vacation through next week.
from homeserver.
The issue here is that base64.NewEncoder writes to the provided buffer in blocks of 4 bytes, and must be manually closed to flush any remaining bytes of less than a block of 4, so you're ending up with only a 30 byte value.
Looks like you can fix it by either calling Close
on the encoder, or by using EncodeToString
instead:
encoded := base64.StdEncoding.EncodeToString(b)
fmt.Println(encoded)
I think it'd be useful for Ruma's CLI to have a command to easily generate a value suitable for use as the macaroon secret key, so I'm going to leave this issue open to remind me to do that.
from homeserver.
My bad, I should really read the docs more thoroughly. Still bothers me that defer
won't work in this context.
Obsoleted by #267dfd9, but here is my patched code:
package main
import (
"bytes"
"crypto/rand"
"encoding/base64"
"fmt"
"log"
)
// Macaroon type
type Macaroon []byte
// NewMacaroon returns a random Macaroon
func NewMacaroon() ([]byte, error) {
b := make([]byte, 32)
_, err := rand.Read(b)
if err != nil {
return nil, err
}
buf := bytes.Buffer{}
w := base64.NewEncoder(base64.StdEncoding, &buf)
_, err = w.Write(b)
if err != nil {
return nil, err
}
w.Close()
return buf.Bytes(), nil
}
func main() {
m, err := NewMacaroon()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(m))
}
from homeserver.
Related Issues (20)
- Switch from PgTimestamp to SystemTime. HOT 5
- Spliting Room::create() into small functions HOT 3
- Sending m.room.member and m.presence events again after changing avatar or displayname HOT 3
- Tracking issue presence HOT 2
- Try data driven test in ruma using macro_rules. HOT 2
- Implement reason field for kick and ban endpoints HOT 1
- Don't allow registering usernames with uppercase letters HOT 5
- [DOCKER] Problem running server HOT 9
- Limit the timeline length from within the SQL query
- The login request parameters shouldn't be wrapped in an `auth` object
- Activate rust incremental build during development
- An empty profile needs to be a created for a new user
- Use empty JSON object as the default response
- Things blocking or slowing progress of Ruma HOT 23
- What's the status of this project? HOT 1
- Distributed Ruma and its distribution ;)
- Project goals HOT 10
- Current status? HOT 3
- Look for config file in /etc HOT 3
- Ruma vs Dendrite HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from homeserver.