Documentation
¶
Overview ¶
Package objectid decodes a MongoDB ObjectId into its embedded fields — most usefully its **creation timestamp**. A 12-byte ObjectId is the default _id of every MongoDB document, and it is not opaque: its first four bytes are the Unix-second creation time. ObjectIds leak into URLs, REST API parameters, logs, and exported documents, so a captured ObjectId reveals when its record was created (and, via the trailing counter, supports record-enumeration / timing inference). This is the MongoDB analogue of uuid_decode's timestamp/info extraction, and the completion of the ObjectId rendering in mongodb_decode / bson_decode (which surface it only as raw hex). Pure offline transform; no network or device.
Wrap-vs-native judgement ¶
Native. An ObjectId is 12 bytes with a fixed layout (BSON spec): a 4-byte big-endian Unix-second timestamp, a 5-byte per-process random value, and a 3-byte big-endian counter. Decoding is hex parsing + a uint32 read — there is nothing to wrap. Consistent with the other in-tree identifier decoders (internal/uuidinfo).
Verifiable / no confidently-wrong output ¶
The timestamp — the one recoverable, security-relevant field — is anchored to the reference pymongo `ObjectId.generation_time`: 507f1f77bcf86cd799439011 → 2012-10-17T21:13:27Z, 65a1b2c3d4e5f60718293a4b → 2024-01-12T21:44:35Z. The random and counter fields are surfaced raw (hex / integer); the legacy pre-3.4 machine-id/process-id split of those bytes is deprecated and deliberately NOT asserted (it would be a confidently-wrong interpretation on a modern ObjectId). A string that is not exactly 24 hex digits is rejected.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result struct {
ObjectID string `json:"objectid"` // canonical lowercase 24-hex
TimestampUTC string `json:"timestamp_utc"`
UnixSeconds int64 `json:"unix_seconds"`
RandomHex string `json:"random_hex"` // bytes 4-8 (5-byte per-process value)
Counter int `json:"counter"` // bytes 9-11 (3-byte big-endian)
Note string `json:"note,omitempty"`
}
Result is the decoded view of a MongoDB ObjectId.