Example #1
0
func encode(c btncrypt.Cipher, tx inodedb.DBTransaction) (*storedbtx, error) {
	jsonops, err := inodedb.EncodeDBOperationsToJson(tx.Ops)
	if err != nil {
		return nil, fmt.Errorf("Failed to encode dbtx: %v", err)
	}

	env, err := btncrypt.Encrypt(c, jsonops)
	if err != nil {
		return nil, fmt.Errorf("Failed to decrypt OpsJSON: %v", err)
	}

	return &storedbtx{TxID: int64(tx.TxID), OpsJSON: env}, nil
}
Example #2
0
func (txio *DBTransactionLogIO) encode(tx inodedb.DBTransaction) (*datastore.Key, *storedbtx, error) {
	key := txio.encodeKey(tx.TxID)

	jsonops, err := inodedb.EncodeDBOperationsToJson(tx.Ops)
	if err != nil {
		return nil, nil, fmt.Errorf("Failed to encode dbtx: %v", err)
	}

	c := txio.cfg.c
	env, err := btncrypt.Encrypt(c, jsonops)
	if err != nil {
		return nil, nil, fmt.Errorf("Failed to encrypt OpsJSON: %v", err)
	}

	return key, &storedbtx{OpsJSON: env}, nil
}
Example #3
0
func TestEncrypt_Short(t *testing.T) {
	payload := []byte("short string")
	envelope, err := btncrypt.Encrypt(tu.TestCipher(), payload)
	if err != nil {
		t.Errorf("Failed to encrypt: %v", err)
	}

	plain, err := btncrypt.Decrypt(tu.TestCipher(), envelope, len(payload))
	if err != nil {
		t.Errorf("Failed to decrypt: %v", err)
	}

	if !bytes.Equal(plain, payload) {
		t.Errorf("Failed to restore original payload")
	}
}
Example #4
0
func TestEncrypt_Long(t *testing.T) {
	payload := util.RandomBytes(1024 * 1024)

	envelope, err := btncrypt.Encrypt(tu.TestCipher(), payload)
	if err != nil {
		t.Errorf("Failed to encrypt: %v", err)
	}

	plain, err := btncrypt.Decrypt(tu.TestCipher(), envelope, len(payload))
	if err != nil {
		t.Errorf("Failed to decrypt: %v", err)
	}

	if !bytes.Equal(payload, plain) {
		t.Errorf("Failed to restore original payload")
	}
}