summaryrefslogtreecommitdiff
path: root/vendor/github.com/rs
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-09-28 18:30:40 +0100
committerLibravatar GitHub <noreply@github.com>2022-09-28 18:30:40 +0100
commita156188b3eb5cb3da44aa1b7452265f5fa38a607 (patch)
tree7097fa48d56fbabc7c2c8750b1f3bc9321d71c0f /vendor/github.com/rs
parent[bugfix] Fix emphasis being added to emoji shortcodes with markdown parsing (... (diff)
downloadgotosocial-a156188b3eb5cb3da44aa1b7452265f5fa38a607.tar.xz
[chore] update dependencies, bump to Go 1.19.1 (#826)
* update dependencies, bump Go version to 1.19 * bump test image Go version * update golangci-lint * update gotosocial-drone-build * sign * linting, go fmt * update swagger docs * update swagger docs * whitespace * update contributing.md * fuckin whoopsie doopsie * linterino, linteroni * fix followrequest test not starting processor * fix other api/client tests not starting processor * fix remaining tests where processor not started * bump go-runners version * don't check last-webfingered-at, processor may have updated this * update swagger command * update bun to latest version * fix embed to work the same as before with new bun Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
Diffstat (limited to 'vendor/github.com/rs')
-rw-r--r--vendor/github.com/rs/xid/README.md14
-rw-r--r--vendor/github.com/rs/xid/error.go11
-rw-r--r--vendor/github.com/rs/xid/hostid_linux.go5
-rw-r--r--vendor/github.com/rs/xid/id.go107
4 files changed, 91 insertions, 46 deletions
diff --git a/vendor/github.com/rs/xid/README.md b/vendor/github.com/rs/xid/README.md
index 1f886fd7c..5bf462e83 100644
--- a/vendor/github.com/rs/xid/README.md
+++ b/vendor/github.com/rs/xid/README.md
@@ -2,9 +2,9 @@
[![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/rs/xid) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/rs/xid/master/LICENSE) [![Build Status](https://travis-ci.org/rs/xid.svg?branch=master)](https://travis-ci.org/rs/xid) [![Coverage](http://gocover.io/_badge/github.com/rs/xid)](http://gocover.io/github.com/rs/xid)
-Package xid is a globally unique id generator library, ready to be used safely directly in your server code.
+Package xid is a globally unique id generator library, ready to safely be used directly in your server code.
-Xid is using Mongo Object ID algorithm to generate globally unique ids with a different serialization (base64) to make it shorter when transported as a string:
+Xid uses the Mongo Object ID algorithm to generate globally unique ids with a different serialization (base64) to make it shorter when transported as a string:
https://docs.mongodb.org/manual/reference/object-id/
- 4-byte value representing the seconds since the Unix epoch,
@@ -33,7 +33,7 @@ is required so it can be used directly in server's code.
|-------------|-------------|----------------|----------------
| [UUID] | 16 bytes | 36 chars | configuration free, not sortable
| [shortuuid] | 16 bytes | 22 chars | configuration free, not sortable
-| [Snowflake] | 8 bytes | up to 20 chars | needs machin/DC configuration, needs central server, sortable
+| [Snowflake] | 8 bytes | up to 20 chars | needs machine/DC configuration, needs central server, sortable
| [MongoID] | 12 bytes | 24 chars | configuration free, sortable
| xid | 12 bytes | 20 chars | configuration free, sortable
@@ -57,7 +57,7 @@ Best used with [zerolog](https://github.com/rs/zerolog)'s
Notes:
-- Xid is dependent on the system time, a monotonic counter and so is not cryptographically secure. If unpredictability of IDs is important, you should not use Xids. It is worth noting that most of the other UUID like implementations are also not cryptographically secure. You shoud use libraries that rely on cryptographically secure sources (like /dev/urandom on unix, crypto/rand in golang), if you want a truly random ID generator.
+- Xid is dependent on the system time, a monotonic counter and so is not cryptographically secure. If unpredictability of IDs is important, you should not use Xids. It is worth noting that most other UUID-like implementations are also not cryptographically secure. You should use libraries that rely on cryptographically secure sources (like /dev/urandom on unix, crypto/rand in golang), if you want a truly random ID generator.
References:
@@ -66,6 +66,10 @@ References:
- https://blog.twitter.com/2010/announcing-snowflake
- Python port by [Graham Abbott](https://github.com/graham): https://github.com/graham/python_xid
- Scala port by [Egor Kolotaev](https://github.com/kolotaev): https://github.com/kolotaev/ride
+- Rust port by [Jérôme Renard](https://github.com/jeromer/): https://github.com/jeromer/libxid
+- Ruby port by [Valar](https://github.com/valarpirai/): https://github.com/valarpirai/ruby_xid
+- Java port by [0xShamil](https://github.com/0xShamil/): https://github.com/0xShamil/java-xid
+- Dart port by [Peter Bwire](https://github.com/pitabwire): https://pub.dev/packages/xid
## Install
@@ -105,7 +109,7 @@ BenchmarkUUIDv4-2 1000000 1427 ns/op 64 B/op 2 allocs/op
BenchmarkUUIDv4-4 1000000 1452 ns/op 64 B/op 2 allocs/op
```
-Note: UUIDv1 requires a global lock, hence the performence degrading as we add more CPUs.
+Note: UUIDv1 requires a global lock, hence the performance degradation as we add more CPUs.
## Licenses
diff --git a/vendor/github.com/rs/xid/error.go b/vendor/github.com/rs/xid/error.go
new file mode 100644
index 000000000..ea2537493
--- /dev/null
+++ b/vendor/github.com/rs/xid/error.go
@@ -0,0 +1,11 @@
+package xid
+
+const (
+ // ErrInvalidID is returned when trying to unmarshal an invalid ID.
+ ErrInvalidID strErr = "xid: invalid ID"
+)
+
+// strErr allows declaring errors as constants.
+type strErr string
+
+func (err strErr) Error() string { return string(err) }
diff --git a/vendor/github.com/rs/xid/hostid_linux.go b/vendor/github.com/rs/xid/hostid_linux.go
index 7d0c4a9ec..837b20436 100644
--- a/vendor/github.com/rs/xid/hostid_linux.go
+++ b/vendor/github.com/rs/xid/hostid_linux.go
@@ -5,6 +5,9 @@ package xid
import "io/ioutil"
func readPlatformMachineID() (string, error) {
- b, err := ioutil.ReadFile("/sys/class/dmi/id/product_uuid")
+ b, err := ioutil.ReadFile("/etc/machine-id")
+ if err != nil || len(b) == 0 {
+ b, err = ioutil.ReadFile("/sys/class/dmi/id/product_uuid")
+ }
return string(b), err
}
diff --git a/vendor/github.com/rs/xid/id.go b/vendor/github.com/rs/xid/id.go
index 466faf262..1f536b415 100644
--- a/vendor/github.com/rs/xid/id.go
+++ b/vendor/github.com/rs/xid/id.go
@@ -47,7 +47,6 @@ import (
"crypto/rand"
"database/sql/driver"
"encoding/binary"
- "errors"
"fmt"
"hash/crc32"
"io/ioutil"
@@ -55,6 +54,7 @@ import (
"sort"
"sync/atomic"
"time"
+ "unsafe"
)
// Code inspired from mgo/bson ObjectId
@@ -72,9 +72,6 @@ const (
)
var (
- // ErrInvalidID is returned when trying to unmarshal an invalid ID
- ErrInvalidID = errors.New("xid: invalid ID")
-
// objectIDCounter is atomically incremented when generating a new ObjectId
// using NewObjectId() function. It's used as a counter part of an id.
// This id is initialized with a random value.
@@ -177,7 +174,13 @@ func FromString(id string) (ID, error) {
func (id ID) String() string {
text := make([]byte, encodedLen)
encode(text, id[:])
- return string(text)
+ return *(*string)(unsafe.Pointer(&text))
+}
+
+// Encode encodes the id using base32 encoding, writing 20 bytes to dst and return it.
+func (id ID) Encode(dst []byte) []byte {
+ encode(dst, id[:])
+ return dst
}
// MarshalText implements encoding/text TextMarshaler interface
@@ -192,32 +195,37 @@ func (id ID) MarshalJSON() ([]byte, error) {
if id.IsNil() {
return []byte("null"), nil
}
- text, err := id.MarshalText()
- return []byte(`"` + string(text) + `"`), err
+ text := make([]byte, encodedLen+2)
+ encode(text[1:encodedLen+1], id[:])
+ text[0], text[encodedLen+1] = '"', '"'
+ return text, nil
}
// encode by unrolling the stdlib base32 algorithm + removing all safe checks
func encode(dst, id []byte) {
- dst[0] = encoding[id[0]>>3]
- dst[1] = encoding[(id[1]>>6)&0x1F|(id[0]<<2)&0x1F]
- dst[2] = encoding[(id[1]>>1)&0x1F]
- dst[3] = encoding[(id[2]>>4)&0x1F|(id[1]<<4)&0x1F]
- dst[4] = encoding[id[3]>>7|(id[2]<<1)&0x1F]
- dst[5] = encoding[(id[3]>>2)&0x1F]
- dst[6] = encoding[id[4]>>5|(id[3]<<3)&0x1F]
- dst[7] = encoding[id[4]&0x1F]
- dst[8] = encoding[id[5]>>3]
- dst[9] = encoding[(id[6]>>6)&0x1F|(id[5]<<2)&0x1F]
- dst[10] = encoding[(id[6]>>1)&0x1F]
- dst[11] = encoding[(id[7]>>4)&0x1F|(id[6]<<4)&0x1F]
- dst[12] = encoding[id[8]>>7|(id[7]<<1)&0x1F]
- dst[13] = encoding[(id[8]>>2)&0x1F]
- dst[14] = encoding[(id[9]>>5)|(id[8]<<3)&0x1F]
- dst[15] = encoding[id[9]&0x1F]
- dst[16] = encoding[id[10]>>3]
- dst[17] = encoding[(id[11]>>6)&0x1F|(id[10]<<2)&0x1F]
- dst[18] = encoding[(id[11]>>1)&0x1F]
+ _ = dst[19]
+ _ = id[11]
+
dst[19] = encoding[(id[11]<<4)&0x1F]
+ dst[18] = encoding[(id[11]>>1)&0x1F]
+ dst[17] = encoding[(id[11]>>6)&0x1F|(id[10]<<2)&0x1F]
+ dst[16] = encoding[id[10]>>3]
+ dst[15] = encoding[id[9]&0x1F]
+ dst[14] = encoding[(id[9]>>5)|(id[8]<<3)&0x1F]
+ dst[13] = encoding[(id[8]>>2)&0x1F]
+ dst[12] = encoding[id[8]>>7|(id[7]<<1)&0x1F]
+ dst[11] = encoding[(id[7]>>4)&0x1F|(id[6]<<4)&0x1F]
+ dst[10] = encoding[(id[6]>>1)&0x1F]
+ dst[9] = encoding[(id[6]>>6)&0x1F|(id[5]<<2)&0x1F]
+ dst[8] = encoding[id[5]>>3]
+ dst[7] = encoding[id[4]&0x1F]
+ dst[6] = encoding[id[4]>>5|(id[3]<<3)&0x1F]
+ dst[5] = encoding[(id[3]>>2)&0x1F]
+ dst[4] = encoding[id[3]>>7|(id[2]<<1)&0x1F]
+ dst[3] = encoding[(id[2]>>4)&0x1F|(id[1]<<4)&0x1F]
+ dst[2] = encoding[(id[1]>>1)&0x1F]
+ dst[1] = encoding[(id[1]>>6)&0x1F|(id[0]<<2)&0x1F]
+ dst[0] = encoding[id[0]>>3]
}
// UnmarshalText implements encoding/text TextUnmarshaler interface
@@ -230,7 +238,9 @@ func (id *ID) UnmarshalText(text []byte) error {
return ErrInvalidID
}
}
- decode(id, text)
+ if !decode(id, text) {
+ return ErrInvalidID
+ }
return nil
}
@@ -241,23 +251,40 @@ func (id *ID) UnmarshalJSON(b []byte) error {
*id = nilID
return nil
}
+ // Check the slice length to prevent panic on passing it to UnmarshalText()
+ if len(b) < 2 {
+ return ErrInvalidID
+ }
return id.UnmarshalText(b[1 : len(b)-1])
}
-// decode by unrolling the stdlib base32 algorithm + removing all safe checks
-func decode(id *ID, src []byte) {
- id[0] = dec[src[0]]<<3 | dec[src[1]]>>2
- id[1] = dec[src[1]]<<6 | dec[src[2]]<<1 | dec[src[3]]>>4
- id[2] = dec[src[3]]<<4 | dec[src[4]]>>1
- id[3] = dec[src[4]]<<7 | dec[src[5]]<<2 | dec[src[6]]>>3
- id[4] = dec[src[6]]<<5 | dec[src[7]]
- id[5] = dec[src[8]]<<3 | dec[src[9]]>>2
- id[6] = dec[src[9]]<<6 | dec[src[10]]<<1 | dec[src[11]]>>4
- id[7] = dec[src[11]]<<4 | dec[src[12]]>>1
- id[8] = dec[src[12]]<<7 | dec[src[13]]<<2 | dec[src[14]]>>3
- id[9] = dec[src[14]]<<5 | dec[src[15]]
- id[10] = dec[src[16]]<<3 | dec[src[17]]>>2
+// decode by unrolling the stdlib base32 algorithm + customized safe check.
+func decode(id *ID, src []byte) bool {
+ _ = src[19]
+ _ = id[11]
+
id[11] = dec[src[17]]<<6 | dec[src[18]]<<1 | dec[src[19]]>>4
+ id[10] = dec[src[16]]<<3 | dec[src[17]]>>2
+ id[9] = dec[src[14]]<<5 | dec[src[15]]
+ id[8] = dec[src[12]]<<7 | dec[src[13]]<<2 | dec[src[14]]>>3
+ id[7] = dec[src[11]]<<4 | dec[src[12]]>>1
+ id[6] = dec[src[9]]<<6 | dec[src[10]]<<1 | dec[src[11]]>>4
+ id[5] = dec[src[8]]<<3 | dec[src[9]]>>2
+ id[4] = dec[src[6]]<<5 | dec[src[7]]
+ id[3] = dec[src[4]]<<7 | dec[src[5]]<<2 | dec[src[6]]>>3
+ id[2] = dec[src[3]]<<4 | dec[src[4]]>>1
+ id[1] = dec[src[1]]<<6 | dec[src[2]]<<1 | dec[src[3]]>>4
+ id[0] = dec[src[0]]<<3 | dec[src[1]]>>2
+
+ // Validate that there are no discarer bits (padding) in src that would
+ // cause the string-encoded id not to equal src.
+ var check [4]byte
+
+ check[3] = encoding[(id[11]<<4)&0x1F]
+ check[2] = encoding[(id[11]>>1)&0x1F]
+ check[1] = encoding[(id[11]>>6)&0x1F|(id[10]<<2)&0x1F]
+ check[0] = encoding[id[10]>>3]
+ return bytes.Equal([]byte(src[16:20]), check[:])
}
// Time returns the timestamp part of the id.