GoSkeletonPy

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 7 Imported by: 0

README

GoSkeletonPy

GoSkeletonPy is a project that allows you to generate a skeletonized file from a Python file and restore it. This is done by encrypting the Python file using AES and storing it in a file, then replacing all the function bodies in the original file with .... The original file can be restored from the skeleton file.

Example

Original File
# test.py
def add(a, b):
    return a + b
    
valueA = 5
    
def sub(a, b):
    return a - b
Skeletonized File
# test.py
def add(a, b):
    ...
    
valueA = ...
    
def sub(a, b):
    ...

Usage

Here's a basic usage example:

package main

import (
    "github.com/KilianSen/GoSkeletonPy"
	"time"
)

func main() {
	// Generate a skeleton file from a python file
	println("Generating skeleton file...")
	skeleton, err := GoSkeletonPy.FileToSkeleton("./test/test.py", "", "")
	if err != nil {
		panic(err)
	}
	println(skeleton)

	// sleep for 5 seconds
	time.Sleep(5 * time.Second)

	file, err := GoSkeletonPy.RestoreSkeletonFile("./test/test.skeletonpy", "", "")
	if err != nil {
		panic(err)
	}

	println(file)

}

Documentation

Index

Constants

View Source
const DefaultSkeletonFileExtension = "skeletonpy"

DefaultSkeletonFileExtension is the default file extension for the skeleton file

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(data []byte, password string) ([]byte, error)

Decrypt takes a byte slice of data and a password string as input. It extracts the salt from the data and uses it along with the password to derive an AES key using Argon2. It then creates a new GCM cipher with the derived key. The nonce and the ciphertext are extracted from the data, and the ciphertext is decrypted using the GCM cipher and the nonce. The resulting plaintext is returned. If an error occurs during any of these steps, it is returned.

func Encrypt

func Encrypt(data []byte, password string) ([]byte, error)

Encrypt takes a byte slice of data and a password string as input. It generates a random salt and uses it along with the password to derive an AES key using Argon2. It then creates a new GCM cipher with the derived key and generates a random nonce. The data is encrypted using the GCM cipher and the nonce, and the resulting ciphertext is returned along with the salt. If an error occurs during any of these steps, it is returned.

func FileToSkeleton

func FileToSkeleton(path, password, ff string) (bool, error)

FileToSkeleton takes a Python file, encrypts it using AES, and stores it in a file. It then opens the original file and replaces all the function bodies with ... If a password is provided, it is used for the encryption. The function returns true if the operation was successful, false otherwise.

func GeneratePythonSkeleton

func GeneratePythonSkeleton(lines []string) []string

GeneratePythonSkeleton takes a slice of strings representing lines of Python code, and returns a new slice where function bodies and variable assignments are replaced with '...'. It also replaces tabs with spaces and removes comments.

func RestoreSkeletonFile

func RestoreSkeletonFile(path string, password string, ff string) (bool, error)

RestoreSkeletonFile takes a skeleton file and restores the original Python file. If a password is provided, it is used for the decryption. The function returns true if the operation was successful, false otherwise.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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