cipher

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

README

pki

Import path: github.com/InsideGallery/core/pki

pki is the legacy import path for the core cipher contract. New code should prefer github.com/InsideGallery/core/pki/cryptor, which exposes the same contract through a focused package name.

The Go package name is cipher, so callers commonly import this path with an alias to avoid confusion with crypto/cipher.

Main API

  • Cipher is the shared interface implemented by the in-tree cipher packages. It requires Encrypt, Decrypt, Kind, ToBinary, and FromBinary.
  • Options carries a requested cipher Kind.
  • Result returns a cipher Kind and operation Data without exposing implementation-specific result types.
  • Encrypt(ctx, cipher, plaintext) checks for a nil cipher, checks ctx.Err(), encrypts with the cipher, and wraps the result.
  • Decrypt(ctx, cipher, ciphertext) performs the same boundary checks for decryption.
  • ErrCipherNotSet is returned, wrapped with context, when the cipher argument is nil.

Usage

package example

import (
	"context"

	"github.com/InsideGallery/core/pki/aesgcm"
	legacycipher "github.com/InsideGallery/core/pki"
)

func roundTrip(ctx context.Context, plaintext []byte) ([]byte, error) {
	cipher, err := aesgcm.New(aesgcm.KeySize32)
	if err != nil {
		return nil, err
	}

	encrypted, err := legacycipher.Encrypt(ctx, cipher, plaintext)
	if err != nil {
		return nil, err
	}

	decrypted, err := legacycipher.Decrypt(ctx, cipher, encrypted.Data)
	if err != nil {
		return nil, err
	}

	return decrypted.Data, nil
}

Compatibility Notes

This path remains available for downstream consumers. Add new cipher boundary helpers to pki/cryptor instead of this package so new call sites avoid a local name collision with Go's standard crypto/cipher package.

Documentation

Overview

Package cipher is the legacy import path for core-owned cipher contracts.

New code should import the focused replacement package:

import "github.com/InsideGallery/core/pki/cryptor"

Compatibility: existing cipher contracts remain available for downstream consumers that still import pki. Do not add new cipher boundary helpers here; add them to pki/cryptor so call sites avoid a local name collision with crypto/cipher.

Index

Constants

This section is empty.

Variables

View Source
var ErrCipherNotSet = errors.New("cipher is not set")

ErrCipherNotSet reports a nil cipher dependency.

Functions

This section is empty.

Types

type Cipher

type Cipher interface {
	Encrypt([]byte) ([]byte, error)
	Decrypt([]byte) ([]byte, error)

	Kind() string
	ToBinary() ([]byte, error)
	FromBinary([]byte) (Cipher, error)
}

type Options added in v1.1.0

type Options struct {
	Kind string
}

Options identifies the cipher behavior requested by a consumer.

type Result added in v1.1.0

type Result struct {
	Kind string
	Data []byte
}

Result is the core-owned result shape for cipher operations.

func Decrypt added in v1.1.0

func Decrypt(ctx context.Context, c Cipher, ciphertext []byte) (Result, error)

Decrypt decrypts ciphertext through a Cipher without exposing implementation-specific result types.

func Encrypt added in v1.1.0

func Encrypt(ctx context.Context, c Cipher, plaintext []byte) (Result, error)

Encrypt encrypts plaintext through a Cipher without exposing implementation-specific result types.

Directories

Path Synopsis
Package aes is the legacy AES-GCM import path.
Package aes is the legacy AES-GCM import path.
Package aesgcm provides AES-GCM cipher helpers without colliding with crypto/aes.
Package aesgcm provides AES-GCM cipher helpers without colliding with crypto/aes.
Package cryptor defines core-owned cipher contracts and boundary helpers.
Package cryptor defines core-owned cipher contracts and boundary helpers.
Package mock_cipher is a generated GoMock package.
Package mock_cipher is a generated GoMock package.
Package rsa is the legacy RSA-OAEP import path.
Package rsa is the legacy RSA-OAEP import path.
Package rsaoaep provides RSA-OAEP cipher helpers without colliding with crypto/rsa.
Package rsaoaep provides RSA-OAEP cipher helpers without colliding with crypto/rsa.

Jump to

Keyboard shortcuts

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