Class: AtprotoAuth::Serialization::Base
- Inherits:
-
Object
- Object
- AtprotoAuth::Serialization::Base
- Defined in:
- lib/atproto_auth/serialization/base.rb
Overview
Base serializer that all type-specific serializers inherit from
Direct Known Subclasses
Constant Summary collapse
- CURRENT_VERSION =
1
- SENSITIVE_FIELDS =
[ "access_token", "refresh_token", "private_key", "d", # EC private key component "pkce_verifier" ].freeze
Class Method Summary collapse
-
.deserialize(data) ⇒ Object
Deserialize from storage format.
-
.serialize(obj) ⇒ String
Serialize object to storage format.
Instance Method Summary collapse
-
#deserialize(data) ⇒ Object
Deserialize from storage format.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#serialize(obj) ⇒ String
Serialize object to storage format.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
40 41 42 |
# File 'lib/atproto_auth/serialization/base.rb', line 40 def initialize @encryption = Encryption::Service.new end |
Class Method Details
.deserialize(data) ⇒ Object
Deserialize from storage format
35 36 37 |
# File 'lib/atproto_auth/serialization/base.rb', line 35 def deserialize(data) new.deserialize(data) end |
.serialize(obj) ⇒ String
Serialize object to storage format
28 29 30 |
# File 'lib/atproto_auth/serialization/base.rb', line 28 def serialize(obj) new.serialize(obj) end |
Instance Method Details
#deserialize(data) ⇒ Object
Deserialize from storage format
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/atproto_auth/serialization/base.rb', line 69 def deserialize(data) parsed = parse_json(data) validate_serialized_data!(parsed) # Decrypt sensitive fields decrypt_sensitive_fields!(parsed) # Deserialize according to version deserialize_version(parsed) end |
#serialize(obj) ⇒ String
Serialize object to storage format
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/atproto_auth/serialization/base.rb', line 47 def serialize(obj) validate_object!(obj) # First serialize the object data = { version: CURRENT_VERSION, type: type_identifier, created_at: Time.now.utc.iso8601, updated_at: Time.now.utc.iso8601, data: serialize_data(obj) } # Then encrypt sensitive fields encrypt_sensitive_fields!(data) # Finally convert to JSON JSON.generate(data) end |