railscookie

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

A small library for dealing with Ruby on Rails cookies in Golang.

Currently only version 5 cookies are supported.

License

Copyright 2023 Zane van Iperen

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const (
	DefaultSignedCookieSalt          = "signed cookie"
	DefaultEncryptedCookieSalt       = "encrypted cookie"
	DefaultEncryptedSignedCookieSalt = "signed encrypted cookie"

	SessionContextKey = "rails_session"
)

Variables

This section is empty.

Functions

func ApplySession

func ApplySession(dec CookieCoder, req *http.Request) *http.Request

func DecodeCookie

func DecodeCookie(cc CookieCoder, ck *http.Cookie, ignoreValidity bool) (string, error)

func DecodeString

func DecodeString(cc CookieCoder, s string) (string, error)

func DecryptCookie

func DecryptCookie(cc CookieCoder, ck *http.Cookie, ignoreValidity bool) (string, error)

func DecryptString

func DecryptString(cc CookieCoder, s string) (string, error)

func EncodeString

func EncodeString(cc CookieCoder, s string) string

func EncryptString

func EncryptString(cc CookieCoder, s string) (string, error)

func WithSession

func WithSession(handler http.Handler, dec CookieCoder) http.Handler

Types

type Configuration

type Configuration struct {
	SecretKeyBase             string
	SignedCookieSalt          string
	EncryptedSignedCookieSalt string
	EncryptedCookieSalt       string
	RNG                       io.Reader
}

func DefaultConfiguration

func DefaultConfiguration() Configuration

type CookieCoder

type CookieCoder interface {
	Decode(s string) ([]byte, error)
	Encode(data []byte) string

	Decrypt(s string) ([]byte, error)
	Encrypt(data []byte) (string, error)
}

func NewRails5CookieCoder

func NewRails5CookieCoder(cfg Configuration) (CookieCoder, error)

type Session

type Session struct {
	SessionID string `json:"session_id"`
	CSRFToken string `json:"_csrf_token"`
	LastBGSet int64  `json:"last_bg_set"`
	BG        int64  `json:"bg"`
}

func DecryptSessionCookie

func DecryptSessionCookie(cc CookieCoder, ck *http.Cookie, ignoreValidity bool) (*Session, error)

func RetrieveSession

func RetrieveSession(ctx context.Context) *Session

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL