001package com.nimbusds.jose.crypto.bc; 002 003 004import org.bouncycastle.jce.provider.BouncyCastleProvider; 005 006 007/** 008 * BouncyCastle JCA provider singleton, intended to prevent memory leaks by 009 * ensuring a single instance is loaded at all times. Application code that 010 * needs a BouncyCastle JCA provider should use the {@link #getInstance()} 011 * method to obtain an instance. 012 * 013 * @author Vladimir Dzhuvinov 014 */ 015public final class BouncyCastleProviderSingleton { 016 017 018 /** 019 * The BouncyCastle provider, lazily instantiated. 020 */ 021 private static BouncyCastleProvider bouncyCastleProvider; 022 023 024 /** 025 * Prevents external instantiation. 026 */ 027 private BouncyCastleProviderSingleton() { } 028 029 030 /** 031 * Returns a BouncyCastle JCA provider instance. 032 * 033 * @return The BouncyCastle JCA provider instance. 034 */ 035 public static BouncyCastleProvider getInstance() { 036 037 if (bouncyCastleProvider != null) { 038 039 return bouncyCastleProvider; 040 041 } else { 042 bouncyCastleProvider = new BouncyCastleProvider(); 043 return bouncyCastleProvider; 044 } 045 } 046}