Documentation
¶
Index ¶
Constants ¶
const ( // ContentTypeUserPreferences for items that holds user's preferences. ContentTypeUserPreferences = "SN|UserPreferences" // ContentTypePrivileges for items that holds note's privileges. ContentTypePrivileges = "SN|Privileges" // ContentTypeComponent are items that describes an editor extension. ContentTypeComponent = "SN|Component" // ContentTypeNote are the items with user's written data. ContentTypeNote = "Note" )
Variables ¶
var ( // ErrUnsupportedVersion is raised when user params version is lesser than `002`. ErrUnsupportedVersion = errors.New("libsf: unsupported version") // ErrLowPasswordCost occurred when cost of password is too low for the used KDF. ErrLowPasswordCost = errors.New("libsf: low password cost") )
Functions ¶
func GenerateItemEncryptionKey ¶
GenerateItemEncryptionKey generates a key that will be split in half, each being 256 bits. So total length will need to be 512.
func GenerateRandomBytes ¶
GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func TimeFromToken ¶
TimeFromToken retrieves datetime from cursor/sync token.
func TokenFromTime ¶
TokenFromTime generates cursor/sync token for given time.
Types ¶
type Auth ¶
type Auth interface { // Emailo returns the email used for authentication. Email() string // IntegrityCheck checks if the Auth params are valid. IntegrityCheck() error // SymmetricKeyPair returns the password, master_key and auth_key for the given uip (plaintext password of the user). // https://github.com/standardfile/standardfile.github.io/blob/master/doc/spec.md#client-instructions SymmetricKeyPair(uip string) (pw, mk, ak string) }
An Auth holds all the params needed to create the credentials and cipher keys.
type Client ¶
type Client interface { // GetAuthParams returns the parameters of a user from StandardFile server. GetAuthParams(email string) (Auth, error) // Login connects the Client to the StandardFile server. Login(email, password string) error // BearerToken returns the authentication used for requests sent to the StandardFile server. BearerToken() string // SetBearerToken sets the authentication used for requests sent to the StandardFile server. SetBearerToken(token string) // SyncItems synchronizes local items with the StandardFile server. SyncItems(si SyncItems) (SyncItems, error) }
A Client defines all interactions that can be performed on a StandardFile server.
func NewDefaultClient ¶
NewDefaultClient returns a new Client with default HTTP client.
type Item ¶
type Item struct { ID string `json:"uuid"` CreatedAt *time.Time `json:"created_at"` UpdatedAt *time.Time `json:"updated_at"` UserID string `json:"user_uuid"` Content string `json:"content"` ContentType string `json:"content_type"` EncryptedItemKey string `json:"enc_item_key"` Deleted bool `json:"deleted"` // Internal AuthParams Auth Note *Note `json:"-"` // contains filtered or unexported fields }
An Item holds all the data created by end user.
type Note ¶
type Note struct { Title string `json:"title"` Text string `json:"text"` PreviewPlain string `json:"preview_plain"` PreviewHTML string `json:"preview_html"` References json.RawMessage `json:"references"` // unstructured data AppData json.RawMessage `json:"appData"` // unstructured data // contains filtered or unexported fields }
A Note is plaintext Item content.
func (*Note) GetSortingField ¶
GetSortingField returns the field on which all notes are sorted. Only for `SN|UserPreferences` items, it returns an empty string if nothing found.
func (*Note) ParseRaw ¶
ParseRaw parses unstructured raw fields. Needed before using other methods on Note object.
func (*Note) SaveRaw ¶
func (n *Note) SaveRaw()
SaveRaw persists the unstructured fields to raw data.
func (*Note) SetUpdatedAtNow ¶
func (n *Note) SetUpdatedAtNow()
SetUpdatedAtNow sets current time as last update time.
type SFError ¶
type SFError struct { StatusCode int Err struct { Message string `json:"message"` } `json:"error"` }
An SFError reprensents an HTTP error returned by StandardFile server.
type SyncItems ¶
type SyncItems struct { // Common fields ComputeIntegrity bool `json:"compute_integrity"` Limit int `json:"limit"` SyncToken string `json:"sync_token"` CursorToken string `json:"cursor_token"` ContentType string `json:"content_type"` // optional, only return items of these type if present // Fields used for request Items []*Item `json:"items"` // Fields used in response Retrieved []*Item `json:"retrieved_items"` Saved []*Item `json:"saved_items"` Unsaved []*UnsavedItem `json:"unsaved"` }
A SyncItems is used when a client want to sync items.
func NewSyncItems ¶
func NewSyncItems() SyncItems
NewSyncItems returns an empty SyncItems with initilized defaults.
type UnsavedItem ¶
type UnsavedItem struct { Item Item `json:"item"` Error struct { Message string `json:"message"` Tag string `json:"tag"` } `json:"error"` }
An UnsavedItem is an object containing an item that has not been saved.