summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/rs/xid
diff options
context:
space:
mode:
authorWim <wim@42.be>2023-08-05 20:43:19 +0200
committerGitHub <noreply@github.com>2023-08-05 20:43:19 +0200
commit56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch)
treeb1355645342667209263cbd355dc0b4254f1e8fe /vendor/github.com/rs/xid
parent9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff)
downloadmatterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.gz
matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.bz2
matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.zip
Update dependencies and remove old matterclient lib (#2067)HEADmaster
Diffstat (limited to 'vendor/github.com/rs/xid')
-rw-r--r--vendor/github.com/rs/xid/.golangci.yml5
-rw-r--r--vendor/github.com/rs/xid/README.md3
-rw-r--r--vendor/github.com/rs/xid/id.go41
3 files changed, 28 insertions, 21 deletions
diff --git a/vendor/github.com/rs/xid/.golangci.yml b/vendor/github.com/rs/xid/.golangci.yml
new file mode 100644
index 00000000..7929600a
--- /dev/null
+++ b/vendor/github.com/rs/xid/.golangci.yml
@@ -0,0 +1,5 @@
+run:
+ tests: false
+
+output:
+ sort-results: true
diff --git a/vendor/github.com/rs/xid/README.md b/vendor/github.com/rs/xid/README.md
index 5bf462e8..974e67d2 100644
--- a/vendor/github.com/rs/xid/README.md
+++ b/vendor/github.com/rs/xid/README.md
@@ -70,6 +70,9 @@ References:
- 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
+- PostgreSQL port by [Rasmus Holm](https://github.com/crholm): https://github.com/modfin/pg-xid
+- Swift port by [Uditha Atukorala](https://github.com/uditha-atukorala): https://github.com/uditha-atukorala/swift-xid
+- C++ port by [Uditha Atukorala](https://github.com/uditha-atukorala): https://github.com/uditha-atukorala/libxid
## Install
diff --git a/vendor/github.com/rs/xid/id.go b/vendor/github.com/rs/xid/id.go
index 1f536b41..fcd7a041 100644
--- a/vendor/github.com/rs/xid/id.go
+++ b/vendor/github.com/rs/xid/id.go
@@ -43,7 +43,7 @@ package xid
import (
"bytes"
- "crypto/md5"
+ "crypto/sha256"
"crypto/rand"
"database/sql/driver"
"encoding/binary"
@@ -72,13 +72,11 @@ const (
)
var (
- // 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.
+ // objectIDCounter is atomically incremented when generating a new ObjectId. It's
+ // used as the counter part of an id. This id is initialized with a random value.
objectIDCounter = randInt()
- // machineId stores machine id generated once and used in subsequent calls
- // to NewObjectId function.
+ // machineID is generated once and used in subsequent calls to the New* functions.
machineID = readMachineID()
// pid stores the current process id
@@ -107,9 +105,9 @@ func init() {
}
}
-// readMachineId generates machine id and puts it into the machineId global
-// variable. If this function fails to get the hostname, it will cause
-// a runtime error.
+// readMachineID generates a machine ID, derived from a platform-specific machine ID
+// value, or else the machine's hostname, or else a randomly-generated number.
+// It panics if all of these methods fail.
func readMachineID() []byte {
id := make([]byte, 3)
hid, err := readPlatformMachineID()
@@ -117,7 +115,7 @@ func readMachineID() []byte {
hid, err = os.Hostname()
}
if err == nil && len(hid) != 0 {
- hw := md5.New()
+ hw := sha256.New()
hw.Write([]byte(hid))
copy(id, hw.Sum(nil))
} else {
@@ -148,7 +146,7 @@ func NewWithTime(t time.Time) ID {
var id ID
// Timestamp, 4 bytes, big endian
binary.BigEndian.PutUint32(id[:], uint32(t.Unix()))
- // Machine, first 3 bytes of md5(hostname)
+ // Machine ID, 3 bytes
id[4] = machineID[0]
id[5] = machineID[1]
id[6] = machineID[2]
@@ -239,6 +237,7 @@ func (id *ID) UnmarshalText(text []byte) error {
}
}
if !decode(id, text) {
+ *id = nilID
return ErrInvalidID
}
return nil
@@ -264,6 +263,10 @@ func decode(id *ID, src []byte) bool {
_ = id[11]
id[11] = dec[src[17]]<<6 | dec[src[18]]<<1 | dec[src[19]]>>4
+ // check the last byte
+ if encoding[(id[11]<<4)&0x1F] != src[19] {
+ return false
+ }
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
@@ -275,16 +278,7 @@ func decode(id *ID, src []byte) bool {
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[:])
+ return true
}
// Time returns the timestamp part of the id.
@@ -344,6 +338,11 @@ func (id ID) IsNil() bool {
return id == nilID
}
+// Alias of IsNil
+func (id ID) IsZero() bool {
+ return id.IsNil()
+}
+
// NilID returns a zero value for `xid.ID`.
func NilID() ID {
return nilID